Commit 48be7663 by german

Rutas de almacenamiento local de audio e imagen cambiadas(Falta pulir para…

Rutas de almacenamiento local de audio e imagen cambiadas(Falta pulir para cuando añades un picto nuevo)
parent acd70e98
...@@ -107,10 +107,11 @@ public class PictoMenu { ...@@ -107,10 +107,11 @@ public class PictoMenu {
} }
public void setPicto(int row, int col, int cat, String expression, Bitmap bitmap){ public void setPicto(int row, int col, int cat, String expression, Bitmap bitmap, int id_picto){
Intent intent = new Intent(activity, EditPictoActivity.class); Intent intent = new Intent(activity, EditPictoActivity.class);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, expression); intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, expression);
intent.putExtra(Picto.JSON_ATTTRS.STUPICTO_ID,id_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()) {
intent.putExtra(Picto.JSON_ATTTRS.CATEGORY, cat); intent.putExtra(Picto.JSON_ATTTRS.CATEGORY, cat);
...@@ -297,7 +298,7 @@ public class PictoMenu { ...@@ -297,7 +298,7 @@ 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())); setPicto(p.get_row(),p.get_column(),p.get_category(),p.get_translation(),p.get_bitmap(PCBcontext.getContext()),p.get_stupicto_id());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -1168,6 +1168,7 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1168,6 +1168,7 @@ protected void showOnlyTape(boolean onlyTape) {
} }
//TODO: Añadir ruta de audio
/** /**
* función para la edición de un texto asociado a una nueva imagen y guardar el nuevo picto * función para la edición de un texto asociado a una nueva imagen y guardar el nuevo picto
*/ */
......
...@@ -2,8 +2,6 @@ package com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper; ...@@ -2,8 +2,6 @@ package com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
...@@ -28,21 +26,14 @@ import android.view.Window; ...@@ -28,21 +26,14 @@ import android.view.Window;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.grammar.iLocalPicto;
import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.tabletlibrary.R; import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.BotonCircular; import com.yottacode.pictogram.tabletlibrary.gui.communicator.BotonCircular;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.PictogramActivity;
import com.yottacode.pictogram.tabletlibrary.gui.login.MainActivity;
import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.tools.GUITools; import com.yottacode.tools.GUITools;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
...@@ -50,7 +41,6 @@ import java.io.File; ...@@ -50,7 +41,6 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream;
import pl.droidsonroids.gif.GifTextView; import pl.droidsonroids.gif.GifTextView;
...@@ -63,11 +53,12 @@ import static java.lang.Thread.sleep; ...@@ -63,11 +53,12 @@ import static java.lang.Thread.sleep;
public class EditPictoActivity extends Activity { public class EditPictoActivity extends Activity {
private boolean editar; private boolean editar;
private int id_picto;
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;
private static final String DEBUG_MESSAGE = "Pruebas"; private 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; public static final int FINISH_EDIT = 2500;
...@@ -92,7 +83,11 @@ public class EditPictoActivity extends Activity { ...@@ -92,7 +83,11 @@ public class EditPictoActivity extends Activity {
//For Audio/////////////////////////////////////////////////////////////////////////// //For Audio///////////////////////////////////////////////////////////////////////////
private static final int REQUEST_RECORD_AUDIO_PERMISSION = 200; private static final int REQUEST_RECORD_AUDIO_PERMISSION = 200;
private static String mFileName = null;
private static String previewAudioPath = null;
private String dirImagePath = null;
private String dirAudioPath = null;
private MediaRecorder mRecorder = null; private MediaRecorder mRecorder = null;
private MediaPlayer mPlayer = null; private MediaPlayer mPlayer = null;
...@@ -112,7 +107,7 @@ public class EditPictoActivity extends Activity { ...@@ -112,7 +107,7 @@ public class EditPictoActivity extends Activity {
RecordTask tareaGrabacion; RecordTask tareaGrabacion;
PlayTask tareaReproduccion; PlayTask tareaReproduccion;
//boolean grabando; boolean hayGrabacion;
boolean reproduciendo; boolean reproduciendo;
int tiempoGrabado; int tiempoGrabado;
int tiempoReproducir; int tiempoReproducir;
...@@ -155,8 +150,12 @@ public class EditPictoActivity extends Activity { ...@@ -155,8 +150,12 @@ public class EditPictoActivity extends Activity {
tiempoTotal = tiempoGrabado-1; tiempoTotal = tiempoGrabado-1;
barraReproducir.setMax(tiempoTotal); barraReproducir.setMax(tiempoTotal);
botonGrabar.PhidePressedRing(); botonGrabar.PhidePressedRing();
Log.i(DEBUG_MESSAGE,"Fin Grabacion.."+tiempoGrabado);
if(tiempoGrabado>1) hayGrabacion = true ;
else hayGrabacion = false;
reiniciarGrabacion(); reiniciarGrabacion();
Log.i(DEBUG_MESSAGE,"Fin Grabacion.."); //Log.i(DEBUG_MESSAGE,"Fin Grabacion..");
} }
} }
...@@ -201,6 +200,24 @@ public class EditPictoActivity extends Activity { ...@@ -201,6 +200,24 @@ public class EditPictoActivity extends Activity {
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.edit_picto_layout); setContentView(R.layout.edit_picto_layout);
dirImagePath = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_DCIM;
dirImagePath += "/PictoImages";
File fileImage = new File(dirImagePath);
if (!fileImage.exists()) {
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);
if(!fileAudio.exists()){
fileAudio.mkdirs();
}
previewAudioPath = dirAudioPath+File.separator+"test.3gp";
//Log.i(DEBUG_MESSAGE,"filepath"+filepath);
DisplayMetrics metrics = new DisplayMetrics(); DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics); getWindowManager().getDefaultDisplay().getMetrics(metrics);
LinearLayout ll = (LinearLayout) findViewById(R.id.image_layout); LinearLayout ll = (LinearLayout) findViewById(R.id.image_layout);
...@@ -225,7 +242,6 @@ public class EditPictoActivity extends Activity { ...@@ -225,7 +242,6 @@ public class EditPictoActivity extends Activity {
cropImageView.setFixedAspectRatio(true); cropImageView.setFixedAspectRatio(true);
cropImageView.setGuidelines(2); cropImageView.setGuidelines(2);
//cropImageView.setAspectRatio(cropImageView.getWidth(),cropImageView.getHeight());
if (transcription != null && transcription.length() > 0) if (transcription != null && transcription.length() > 0)
legend.setText(transcription); legend.setText(transcription);
...@@ -249,62 +265,7 @@ public class EditPictoActivity extends Activity { ...@@ -249,62 +265,7 @@ public class EditPictoActivity extends Activity {
editar = getIntent().getBooleanExtra("tipo",false); editar = getIntent().getBooleanExtra("tipo",false);
titulo.setText(editar ? R.string.titleCropperEdit : R.string.titleCropperNew); titulo.setText(editar ? R.string.titleCropperEdit : R.string.titleCropperNew);
//Gestion de botones
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (legend.getText().toString().trim().length() > 0) {
final Bitmap croppedImage = cropImageView.getCroppedImage();
//Guardar imagen en galeria y obtener la ruta
try {
String title = getResources().getString(R.string.app_name) + ' ' + legend.getText().toString();
String path = "/storage/emulated/0/DCIM/Camera/"+title+".png";
File imageFile = new File(path);
FileOutputStream outputStream = new FileOutputStream(imageFile);
Bitmap bitmap = Bitmap.createBitmap(cropImageView.getCroppedImage());
bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream);
MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, path, null);
outputStream.flush();
outputStream.close();
Intent intent = getIntent(); //Mandar a pictogram activity el path y el texto de la imagen
intent.putExtra(PATH,path);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, legend.getText().toString());
intent.putExtra(Picto.JSON_ATTTRS.CATEGORY,getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1));
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);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finish(); //Termina la actividad de editar
} else
Toast.makeText(getBaseContext(), R.string.crop_TextRequired, Toast.LENGTH_LONG).show();
}
});
//Si cancela, volver a pictogram activity
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
setResult(RESULT_CANCELED, getIntent());
}
});
// Record to the external cache directory for visibility
mFileName = getFilesDir().getPath();
mFileName += "/audiorecordtest.3gp";
ContentValues values = new ContentValues(3);
values.put(MediaStore.MediaColumns.TITLE, mFileName);
ActivityCompat.requestPermissions(this, permissions, REQUEST_RECORD_AUDIO_PERMISSION); ActivityCompat.requestPermissions(this, permissions, REQUEST_RECORD_AUDIO_PERMISSION);
...@@ -325,13 +286,14 @@ public class EditPictoActivity extends Activity { ...@@ -325,13 +286,14 @@ public class EditPictoActivity extends Activity {
botonReproducir.setEnabled(false); botonReproducir.setEnabled(false);
layoutPreview.setVisibility(View.INVISIBLE); layoutPreview.setVisibility(View.INVISIBLE);
hayGrabacion = false;
reproduciendo = false; reproduciendo = false;
tiempoGrabado = 0; tiempoGrabado = 0;
tiempoReproducir = 0; tiempoReproducir = 0;
tiempoTotal = 0; tiempoTotal = 0;
//TODO: Aqui comprobar si ya hay grabación //TODO: Aqui comprobar si ya hay grabación
//if (hayGrabacion){ //if (hayGrabacionAnterior){
layoutGrabacion.setVisibility(View.VISIBLE); layoutGrabacion.setVisibility(View.VISIBLE);
layoutPreview.setVisibility(View.GONE); layoutPreview.setVisibility(View.GONE);
//}else{ Cargar el audio en el mediaPlayer //}else{ Cargar el audio en el mediaPlayer
...@@ -339,6 +301,77 @@ public class EditPictoActivity extends Activity { ...@@ -339,6 +301,77 @@ public class EditPictoActivity extends Activity {
//layoutPreview.setVisibility(View.VISIBLE); //layoutPreview.setVisibility(View.VISIBLE);
//} //}
//Gestion de botones
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (legend.getText().toString().trim().length() > 0) {
final Bitmap croppedImage = cropImageView.getCroppedImage();
//Guardar imagen en galeria y obtener la ruta
String title = getResources().getString(R.string.app_name) + ' ' + legend.getText().toString();
try {
id_picto = getIntent().getExtras().getInt(Picto.JSON_ATTTRS.STUPICTO_ID);
String filepath = dirImagePath + File.separator + legend.getText().toString() + "_"+id_picto + ".png";
Log.i(DEBUG_MESSAGE,"filepath->"+filepath);
File imageFile = new File(filepath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
Bitmap bitmap = Bitmap.createBitmap(cropImageView.getCroppedImage());
bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream);
outputStream.flush();
outputStream.close();
Intent intent = getIntent(); //Mandar a pictogram activity el path y el texto de la imagen
intent.putExtra(PATH,filepath);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, legend.getText().toString());
intent.putExtra(Picto.JSON_ATTTRS.CATEGORY,getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1));
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);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//String dirAudioPath = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_MUSIC;
//dirAudioPath += "/PictoAudio";
//File dir = Environment.getExternalStorageDirectory();
Log.i(DEBUG_MESSAGE,String.valueOf(hayGrabacion));
if(hayGrabacion) { //Si ha grabado algo -> Ir a renombrarlo
File file = new File(previewAudioPath);
Log.i(DEBUG_MESSAGE,"Hay Grabacion -> Modifica nombre");
Log.i(DEBUG_MESSAGE,file.toString());
if (file.exists()) {
File from = new File(previewAudioPath);
File to = new File(dirAudioPath+File.separator+legend.getText().toString() + "_"+id_picto + "_audio.3gp");
if (from.exists())
from.renameTo(to);
}
}
finish(); //Termina la actividad de editar
} else
Toast.makeText(getBaseContext(), R.string.crop_TextRequired, Toast.LENGTH_LONG).show();
}
});
//Si cancela, volver a pictogram activity
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
setResult(RESULT_CANCELED, getIntent());
}
});
botonGrabar.setOnTouchListener(new View.OnTouchListener() { botonGrabar.setOnTouchListener(new View.OnTouchListener() {
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
...@@ -441,7 +474,7 @@ public class EditPictoActivity extends Activity { ...@@ -441,7 +474,7 @@ public class EditPictoActivity extends Activity {
private void startPlaying() { private void startPlaying() {
mPlayer = new MediaPlayer(); mPlayer = new MediaPlayer();
try { try {
mPlayer.setDataSource(mFileName); mPlayer.setDataSource(previewAudioPath);
mPlayer.prepare(); mPlayer.prepare();
mPlayer.start(); mPlayer.start();
} catch (IOException e) { } catch (IOException e) {
...@@ -458,9 +491,10 @@ public class EditPictoActivity extends Activity { ...@@ -458,9 +491,10 @@ public class EditPictoActivity extends Activity {
mRecorder = new MediaRecorder(); mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
Log.i(DEBUG_MESSAGE,mFileName);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
Log.i(DEBUG_MESSAGE, previewAudioPath);
mRecorder.setOutputFile(previewAudioPath);
try { try {
mRecorder.prepare(); mRecorder.prepare();
...@@ -483,6 +517,7 @@ public class EditPictoActivity extends Activity { ...@@ -483,6 +517,7 @@ public class EditPictoActivity extends Activity {
private void reiniciarGrabacion(){ private void reiniciarGrabacion(){
tiempoGrabado = 0; tiempoGrabado = 0;
textoTGrabacion.setText("00:00 | 00:10"); textoTGrabacion.setText("00:00 | 00:10");
//hayGrabacion = false;
} }
private void reiniciarReproducción(){ private void reiniciarReproducción(){
...@@ -521,8 +556,6 @@ public class EditPictoActivity extends Activity { ...@@ -521,8 +556,6 @@ 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);
//int cat = getIntent().getIntExtra("cat", -1);
Bitmap imagen = null; Bitmap imagen = null;
Bitmap rescaled = null; Bitmap rescaled = null;
switch(requestCode) { switch(requestCode) {
......
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