Issue #171,#172,# terminados (Falta asociar bien el archivo de audio al Media…

Issue #171,#172,# terminados (Falta asociar bien el archivo de audio al Media Player de la actividad)
parent f9daed10
......@@ -59,6 +59,7 @@ public class Picto extends Img {
public static String LEGEND = "legend";
public static String URI_SOUND = "uri_sound";
public static String USER_AVATAR = "user_avatar";
//public static String SCENE = "scene";
}
......@@ -97,7 +98,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 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 user_avatar/*, int scene*/) throws JSONException {
this(id, url, new JSONObject()
.put(JSON_ATTTRS.CATEGORY, cat)
.put(JSON_ATTTRS.COLUMN, column)
......@@ -109,6 +110,7 @@ public class Picto extends Img {
.put(JSON_ATTTRS.STUPICTO_ID,stupicto_id)
.put(JSON_ATTTRS.EXPRESSION,translation)
.put(JSON_ATTTRS.USER_AVATAR,user_avatar)
/*.put(JSON_ATTTRS.SCENE,scene)*/
);
}
public Picto(int id, String url,String translation, String attributes) throws JSONException {
......@@ -348,6 +350,14 @@ public class Picto extends Img {
/**
*
* @return the id of an scene of a picto
*/
/*public int get_id_scene() throws JSONException {
return this.attributes.getInt(JSON_ATTTRS.SCENE);
}
*/
/**
*
* @return the row of the picto
*/
public int get_row() {
......
......@@ -440,7 +440,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,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,user_avatar/*, prev_picto.get_id_scene()*/);
if (path_sound!=null)
new File(path_sound).renameTo(new File(picto.get_audioPath()));
......
......@@ -149,6 +149,8 @@ public class PictoUploader {
try {
JSONObject json_attrs =new JSONObject().put("status",picto.get_status());
if (picto.get_user_avatar()!=null) json_attrs.put(Picto.JSON_ATTTRS.USER_AVATAR,picto.get_user_avatar());
/*json_attrs.put("scene",picto.get_id_scene());*/
if (PCBcontext.getPcbdb().getCurrentUser().has_categories())
json_attrs.put(Picto.JSON_ATTTRS.CATEGORY, picto.get_category())
.put(Picto.JSON_ATTTRS.COLUMN, picto.get_column())
......@@ -157,7 +159,7 @@ public class PictoUploader {
json_attrs.put(Picto.JSON_ATTTRS.CATEGORY, picto.NO_CATEGORY)
.put(Picto.JSON_ATTTRS.FREE_COLUMN, picto.getFreeColumn())
.put(Picto.JSON_ATTTRS.FREE_ROW, picto.getFreeRow());
params.put("json", new JSONObject().put("attributes",json_attrs).put("id_scene",44).toString());
params.put("json", new JSONObject().put("attributes",json_attrs).put("id_scene",50).toString());
} catch (JSONException e) {
e.printStackTrace();
......
......@@ -39,13 +39,16 @@ import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.yottacode.net.RestapiWrapper;
import com.yottacode.pictogram.action.PictosAction;
import com.yottacode.pictogram.action.TalkAction;
import com.yottacode.pictogram.dao.PCBDBHelper;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.grammar.iLocalPicto;
import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.net.NetService;
import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.net.websockets.ActionTalk;
import com.yottacode.pictogram.net.websockets.VocabularyTalk;
......@@ -158,6 +161,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
this.vocabulary.listen(PCBcontext.getRoom(), this, new ActionTalk.iActionListener() {
@Override
public void action(action action, int picto_cat, int picto_id) {
Log.i(this.getClass().getCanonicalName(), action + " from " + picto_cat + "," + picto_id + " catched");
if (action==ActionTalk.iActionListener.action.show) {
Log.i(LOG_TAG,"show message received:"+action.toString());
......@@ -1164,7 +1168,7 @@ protected void showOnlyTape(boolean onlyTape) {
int freeColumn = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.FREE_COLUMN) : getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_COLUMN, -1);
String path_sound = data.getExtras().getString(PictoMenu.PATH_SOUND);
String user_avatar = data.getExtras().getString(Picto.JSON_ATTTRS.USER_AVATAR);
String user_avatar = data.getExtras().getString(Picto.JSON_ATTTRS.USER_AVATAR)/* : getIntent().getStringExtra(Picto.JSON_ATTTRS.USER_AVATAR, "----")*/;
int cat = edit ? data.getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1) : getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1);
......@@ -1188,7 +1192,7 @@ protected void showOnlyTape(boolean onlyTape) {
// Set up the buttons
Log.i(LOG_TAG,"Uploading "+legend+" at row "+row+"/"+freeRow+", col "+col+"/"+freeColumn+" sound "+path_sound );
Log.i("TAG_PRUEBAS","Uploading "+legend+" at row "+row+"/"+freeRow+", col "+col+"/"+freeColumn+" sound "+path_sound +" user_avatar: "+user_avatar);
PCBcontext.getVocabulary().saveLocalPicto(
selectedImagePath,
......@@ -1203,15 +1207,13 @@ protected void showOnlyTape(boolean onlyTape) {
new iLocalPicto() {
@Override
public void saved(Picto localPicto) {
refresh();
try {
if (PCBcontext.is_user_online())
new PictoUploader(localPicto).upload();
} catch (IOException e) {
Log.e(Vocabulary.class.getCanonicalName(), e.getMessage());
}
refresh();
try {
if (PCBcontext.is_user_online())
new PictoUploader(localPicto).upload();
} catch (IOException e) {
Log.e(Vocabulary.class.getCanonicalName(), e.getMessage());
}
}
});
}
......@@ -1223,7 +1225,7 @@ protected void showOnlyTape(boolean onlyTape) {
Intent intent = new Intent(this, EditPictoActivity.class);
/* ByteArrayOutputStream stream = new ByteArrayOutputStream();
/* ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
intent.putExtra(PictoMenu.IMAGE_PICTO, byteArray);*/
......
......@@ -119,7 +119,7 @@ public class EditPictoActivity extends Activity {
private String dirAudioPath = null;
private MediaRecorder mRecorder = null;
private MediaPlayer mPlayer = null;
private MediaPlayer mPlayer;
BotonCircular botonGrabar;
BotonCircular botonReproducir;
......@@ -139,6 +139,7 @@ public class EditPictoActivity extends Activity {
boolean hayGrabacion;
boolean reproduciendo;
boolean borrado; //Para saber si se borra un audio que ya estaba asociado a un picto
int tiempoGrabado;
int tiempoReproducir;
int tiempoTotal;
......@@ -216,6 +217,7 @@ public class EditPictoActivity extends Activity {
protected void onCancelled(){
stopPlaying();
assignFileToPlayer(editar ? (p.getUriSound() != null ? p.get_audioPath() : previewAudioPath) : null);
reiniciarReproducción();
}
}
......@@ -325,15 +327,12 @@ public class EditPictoActivity extends Activity {
layoutGrabacion = (LinearLayout) findViewById(R.id.layout_record);
botonReproducir.setEnabled(false);
layoutPreview.setVisibility(View.INVISIBLE);
hayGrabacion = false;
reproduciendo = false;
tiempoGrabado = 0;
tiempoReproducir = 0;
tiempoTotal = 0;
//String transcription = getIntent().getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
cropImageView.setFixedAspectRatio(true);
cropImageView.setGuidelines(2);
......@@ -347,30 +346,45 @@ public class EditPictoActivity extends Activity {
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_user_avatar()==null ? NO_SUP_TEXT : p.get_user_avatar());
//Si el picto viene con sonido
if(p.getUriSound() != null){
borrado = false;
Log.i(DEBUG_MESSAGE,"Ruta: "+p.getUriSound() +"---Ruta2: "+p.get_audioPath());
Log.i(DEBUG_MESSAGE,"Picto CON sonido asociado");
layoutPreview.setVisibility(View.VISIBLE);
File file = new File(p.get_audioPath());
assignFileToPlayer(file.getPath());
tiempoTotal = mPlayer.getDuration();
hayGrabacion = true;
//tiempoTotal = mPlayer.getDuration();
layoutGrabacion.setVisibility(View.GONE);
}else{
Log.i(DEBUG_MESSAGE,"Picto SIN sonido asociado");
layoutPreview.setVisibility(View.INVISIBLE);
layoutGrabacion.setVisibility(View.VISIBLE);
hayGrabacion = false;
tiempoTotal = 0;
}
}else{
layoutPreview.setVisibility(View.INVISIBLE);
layoutGrabacion.setVisibility(View.VISIBLE);
hayGrabacion = false;
tiempoTotal = 0;
}
legend.setHorizontallyScrolling(false);
legend.setMaxLines(1);
legend.setSingleLine(true);
//Obtener imagen del intent
/*byte[] byteArray = getIntent().getByteArrayExtra(PictoMenu.IMAGE_PICTO);*/
final Bitmap imagePicto = scale_image(BitmapTools.load_temporal());
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);
layoutPreview.setVisibility(View.GONE);
//}else{ Cargar el audio en el mediaPlayer
//layoutGrabacion.setVisibility(View.GONE);
//layoutPreview.setVisibility(View.VISIBLE);
//}
pathNumber = nRandom.nextInt();
supAsociado.setOnClickListener(new View.OnClickListener() {
......@@ -389,12 +403,8 @@ public class EditPictoActivity extends Activity {
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]);
Log.i("TAG_PRUEBS","Sup elegido: "+supAsociado.getText());
mDrawerLayout.closeDrawer(Gravity.RIGHT);
//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());
}
});
......@@ -454,13 +464,11 @@ public class EditPictoActivity extends Activity {
Intent intent = getIntent(); //Mandar a pictogram activity el path y el texto de la 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(PictoMenu.PATH_SOUND,audioPath); //Mandar el path del audio
intent.putExtra(PictoMenu.PATH_SOUND,borrado ? audioPath : p.get_audioPath()); //Mandar el path del audio
Log.e(LOG_TAG, "PATH SOUND:"+audioPath);
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.USER_AVATAR, supAsociado.getText().equals(NO_SUP_TEXT)?null:supAsociado.getText());
//p.setUriSound(audioPath);
intent.putExtra(Picto.JSON_ATTTRS.USER_AVATAR, supAsociado.getText());
setResult(RESULT_OK, intent);
......@@ -487,11 +495,11 @@ public class EditPictoActivity extends Activity {
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
recordSoundOn.play(MediaActionSound.START_VIDEO_RECORDING);
recordSoundOn.play(MediaActionSound.SHUTTER_CLICK);
tareaGrabacion = (RecordTask) new RecordTask().execute(tiempoGrabado);
gifRecord.setBackgroundResource(R.drawable.record_animation);
try { //Para que no capture el sonido del sistema
sleep(500);
sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
......@@ -503,6 +511,8 @@ public class EditPictoActivity extends Activity {
case MotionEvent.ACTION_UP:
gifRecord.setBackgroundResource(R.color.white);
tareaGrabacion.cancel(true);
//mPlayer.setDataSource(previewAudioPath);
assignFileToPlayer(/*mPlayer,*/previewAudioPath);
recordSoundOff.play(MediaActionSound.FOCUS_COMPLETE);
return true;
......@@ -517,7 +527,7 @@ public class EditPictoActivity extends Activity {
if(reproduciendo){
tareaReproduccion.cancel(true);
reproduciendo = false;
Log.i(DEBUG_MESSAGE,"parar");
Log.i(DEBUG_MESSAGE,"Parar");
botonReproducir.setImageResource(android.R.drawable.ic_media_play);
}else{
reproduciendo = true;
......@@ -532,8 +542,20 @@ public class EditPictoActivity extends Activity {
botonBorrar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
layoutGrabacion.setVisibility(View.VISIBLE);
layoutPreview.setVisibility(View.GONE);
borrado = true;
if(hayGrabacion){
mPlayer.release();
if(editar){
if(p.getUriSound() != null) {
Log.i(DEBUG_MESSAGE,"Eliminado->"+p.getUriSound());
p.setUriSound(null);
}
}
Log.i(DEBUG_MESSAGE,"Eliminado->"+previewAudioPath);
layoutGrabacion.setVisibility(View.VISIBLE);
layoutPreview.setVisibility(View.GONE);
hayGrabacion = false;
}
}
});
......@@ -591,20 +613,39 @@ public class EditPictoActivity extends Activity {
}
private void startPlaying() {
private void assignFileToPlayer(String pathReproducir){
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(previewAudioPath);
mPlayer.setDataSource(pathReproducir);
} catch (IOException e) {
e.printStackTrace();
}
}
private void startPlaying(/*MediaPlayer m*/) {
//m = new MediaPlayer();
try {
//mPlayer.setDataSource(pathReproducir);
mPlayer.prepare();
mPlayer.start();
} catch (IOException e) {
Log.e(DEBUG_MESSAGE, "prepare() failed");
} catch (IllegalStateException e){
Log.e(DEBUG_MESSAGE, "Illegal state exception on prepare()");
}
}
private void pausePlay(MediaPlayer m){
if(m.isPlaying()){
m.pause();
}else{
m.start();
}
}
private void stopPlaying() {
mPlayer.release();
mPlayer = null;
private void stopPlaying(/*MediaPlayer m*/) {
mPlayer.reset();
//mPlayer = null;
}
private void startRecording() {
......@@ -651,7 +692,7 @@ public class EditPictoActivity extends Activity {
}
@Override
/*@Override
public void onStop() {
super.onStop();
if (mRecorder != null) {
......@@ -659,11 +700,11 @@ public class EditPictoActivity extends Activity {
mRecorder = null;
}
if (mPlayer != null) {
if (mPlayer!= null) {
mPlayer.release();
mPlayer = null;
}
}
}*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
......
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