Pictogram 1.5 beta

- Refactorización Communicator - Supervisor: ya no son intercambiables
- Botón "play" más grande
- Mensaje informativo "escenario vacio"
- Bug de sonidos breves solventando. Mensaje "mantenga pulsado" implementado
- Reproducción de tiras grabadas completamente con voz grabada y animaciones sincronizadas con la reproducción
parent 19e323e7
......@@ -268,7 +268,7 @@ public class Vocabulary implements Iterable<Picto> {
ImgDownloader downloader = new ImgDownloader(PCBcontext.getContext(), imgListener,ImgDownloader.tsource.remote);
downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imgs);
}
public boolean is_category(Picto p) {Log.e("=","8354"+this.pictos.containsKey(8354));return this.pictos.containsKey(p.get_id()); }
public boolean is_category(Picto p) {return this.pictos.containsKey(p.get_id()); }
public int size() { return this.pictos.size();}
/**
* It includes/updates a new picto to the user collection: download the image from remote or local storage, add the picto to the current vocabulary and update the database
......@@ -387,17 +387,6 @@ public class Vocabulary implements Iterable<Picto> {
public void addPicto(Picto picto) {
LinkedList<Picto> pictos_cat;
Log.e("ADD","P"+picto.get_id()+";cat:"+picto.get_category()+":"+picto.get_translation());
if (picto.get_id()==8354) {
pictos_cat = new LinkedList();
Picto p=get_picto(52366,11039);
pictos_cat.add(p);
this.pictos.put(picto.get_id(), pictos_cat);
Log.e("ADDADD","P"+picto.get_id()+";"+picto.get_translation()+":"+this.pictos.containsKey(picto.get_id())+":"+is_category(picto));
return;
}
Log.e("ADDADD","P"+picto.get_id()+";"+picto.get_translation()+":"+this.pictos.containsKey(8354)+":"+is_category(picto));
if (this.pictos.containsKey(picto.get_category()))
pictos_cat = pictos.get(picto.get_category());
else {
......
......@@ -30,9 +30,11 @@ public class TTSHelper {
private static final String LOG_TAG = TTSHelper.class.getName();
TextToSpeech ttobj=null;
SoundPool sp=null;
Hashtable<String, Integer> recorded_sounds=null;
boolean voice_ok;
public void createTTS(final Context context, String engine, final Locale locale, final String voice) {
if (this.ttobj == null) {
......@@ -52,7 +54,7 @@ public class TTSHelper {
recorded_sounds = new Hashtable<>(3);
}
}
public TTSHelper(Context context, String engine, Locale locale,String voice) {
public TTSHelper(Context context, String engine, Locale locale,String voice) {
createTTS(context ,engine,locale,voice);
}
......@@ -177,10 +179,13 @@ public class TTSHelper {
}
public void playRecord(final File mp3) {
Integer mp3id=this.recorded_sounds.get(mp3.getAbsolutePath());
if (mp3id==null)
addRecord(mp3);
else
sp.play(mp3id.intValue(), 1, 1, 1, 0, 1);
}
}
......@@ -19,6 +19,8 @@
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<application
android:allowBackup="true"
......@@ -67,6 +69,14 @@
android:launchMode="singleTop"
android:screenOrientation="landscape" />
<activity
android:name="com.yottacode.pictogram.supervisor.gui.cropper.EditPictoActivity"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:screenOrientation="landscape" />
</application>
......
package com.yottacode.pictogram.supervisor.gui;
import android.annotation.TargetApi;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.pictogram.tts.TTSHelper;
import java.util.Iterator;
import java.util.LinkedList;
public class TapeAdapter extends BaseAdapter {
private static final String LOG_TAG = TapeAdapter.class.getName();
//private Context mContext;
private LinkedList<Picto> pictoLinkedList;
private boolean play = false;
public TapeAdapter() {
//mContext = c;
pictoLinkedList = new LinkedList<Picto>(); // the list begins empty
}
@Override
public int getCount() {
return pictoLinkedList.size();
}
public Picto getItem(int position) {
// este método debería devolver el objeto que esta en esa posición del
// adapter.
return pictoLinkedList.get(position);
}
public long getItemId(int position) {
// este método debería devolver el id de fila del item que esta en esa
// posición del adapter. No es necesario en este caso más que devolver 0.
return 0;
}
// AÑADIR ITEM AL ADAPTADOR
public int addItem(Picto p) {
pictoLinkedList.add(new Picto(p));
return pictoLinkedList.size()-1;
}
// ELIMINAR ITEM DEL ADAPTADOR
public void deleteItem(int position) {
try {
pictoLinkedList.remove(position);
}catch(IndexOutOfBoundsException e) {
Log.e(LOG_TAG,"Error deleting item from tape adapter:"+e.getMessage());
}
}
// ELIMINAR el último ITEM DEL ADAPTADOR
public Picto deleteLastView() {
Picto picto=null;
// Controlar excepcion al intentar eliminar el último cuando no hay elementos
try {
picto=pictoLinkedList.removeLast();
} catch (ArrayIndexOutOfBoundsException exception) {
Log.e("Excepción", "ArrayIndexOutOfBounds: " + exception.getMessage());
}
return picto;
}
// ELIMINAR TODOS LOS ITEMS DEL ADAPTADOR
public void endPlay() {
if (PCBcontext.getPcbdb().getCurrentUser().delivery()==User.JSON_STUDENT_ATTTRS.delivery.clean)
clear();
play = false;
}
public void clear() {
pictoLinkedList.clear();
notifyDataSetChanged();
}
// DEVUELVE TODOS LOS ELEMENTOS
public LinkedList<Picto> getAll() {
return pictoLinkedList;
}
// Devuelvo la cadena actual como un String
public String getAllAsString() {
String complete = "";
Iterator<Picto> iterator = pictoLinkedList.iterator();
while (iterator.hasNext()) {
Picto current = iterator.next();
complete += " " + current.get_translation();
}
return complete;
}
// DEVUELVE último elemento
public Picto getLastItem() {
return pictoLinkedList.getLast();
}
// Devuelve true o false si tiene o no elementos la lista de pictos
public boolean hasElements() {
return (pictoLinkedList.size() > 0);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View pictoView = PictoItemViewGenerator.getPictoView(
this.pictoLinkedList.get(position),
convertView,
parent, true);
return pictoView;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void ttsAllNew(TTSHelper tts) {
this.play = true;
String input = getAllAsString();
tts.play(input);
}
public boolean play() {
return this.play;
}
}
......@@ -669,7 +669,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
case MotionEvent.ACTION_UP:
if (event.getX() > firstTouchX + 150) { // izquierda a derecha
// Pasa de VocabularyManager a voca
if (PCBcontext.getVocabulary().isVisibleAnyPicto())
if (!PCBcontext.getVocabulary().isVisibleAnyPicto())
Toast.makeText(this, R.string.emptyVocabulary_msg,Toast.LENGTH_LONG).show();
else
nextActivity = new Intent(this, VOCAS.class);
......
......@@ -136,7 +136,7 @@ public class EditPictoActivity extends Activity {
LinearLayout layoutPreview;
LinearLayout layoutGrabacion;
RecordTask tareaGrabacion;
RecordTask tareaGrabacion=null;
PlayTask tareaReproduccion;
boolean hayGrabacion;
......@@ -216,8 +216,8 @@ public class EditPictoActivity extends Activity {
}
protected void onCancelled(){
stopPlaying();
assignFileToPlayer(editar ? ((!borrado && p.get_audioFile()!=null) ? p.get_audioFile() : new File(previewAudioPath)) : null);
stopPlaying();Log.e("onCacelled","B:"+borrado+"aF:"+p+"pp:"+previewAudioPath);
assignFileToPlayer(editar ? ((!borrado && p.get_audioFile()!=null) ? p.get_audioFile() : new File(previewAudioPath)) : new File(previewAudioPath));
reiniciarReproducción();
}
}
......@@ -339,7 +339,7 @@ public class EditPictoActivity extends Activity {
//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.titleCropperEdit);
titulo.setText(editar ? R.string.titleCropperEdit : R.string.titleCropperNew);
//Obtener el picto a editar
if(editar){
......@@ -481,6 +481,14 @@ public class EditPictoActivity extends Activity {
});
botonGrabar.setOnTouchListener(new View.OnTouchListener() {
private void endTareaGrabacion() {
tareaGrabacion.cancel(true);
gifRecord.setBackgroundResource(R.color.white);
recordSoundOff.play(MediaActionSound.FOCUS_COMPLETE);
tareaGrabacion=null;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
......@@ -495,12 +503,16 @@ public class EditPictoActivity extends Activity {
startRecording();
}
}, 500); // 0.5s delay
return true;
case MotionEvent.ACTION_UP:
tareaGrabacion.cancel(true);
gifRecord.setBackgroundResource(R.color.white);
recordSoundOff.play(MediaActionSound.FOCUS_COMPLETE);
if (tareaGrabacion!=null) endTareaGrabacion();
else new Handler().postDelayed(new Runnable() {
@Override
public void run() {
endTareaGrabacion();
}
}, 500); // 0.5s delay
return true;
}
......@@ -597,15 +609,15 @@ public class EditPictoActivity extends Activity {
}
private void assignFileToPlayer(File audio){
Log.i(DEBUG_MESSAGE,"Asignado: "+audio.getPath().toString());
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(new FileInputStream(audio).getFD());
mPlayer.prepare();
tiempoTotal = Math.round(mPlayer.getDuration()/1000);
textoTTotal.setText("00:00 | 00:"+(tiempoTotal == 10 ? tiempoTotal : "0" + tiempoTotal));
barraReproducir.setMax(tiempoTotal);
Log.i(DEBUG_MESSAGE,"Assign.."+tiempoTotal);
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalStateException e){
......@@ -660,7 +672,7 @@ public class EditPictoActivity extends Activity {
private void reiniciarGrabacion(){
tiempoGrabado = 0;
textoTGrabacion.setText("00:00 | 00:10");
textoTGrabacion.setText(getString(R.string.record_time));
}
private void reiniciarReproducción(){
......
......@@ -41,7 +41,7 @@
android:gravity="center"
android:orientation="horizontal">
<com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper.CropImageView
<com.yottacode.pictogram.supervisor.gui.cropper.CropImageView
android:id="@+id/CropImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......@@ -178,7 +178,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Audio:"
android:text="@string/audio"
android:textColor="@color/gray"
android:textSize="20sp" />
......@@ -214,7 +214,7 @@
android:gravity="center"
android:paddingLeft="5dp"
android:paddingRight="16dp"
android:text="00:00 | 00:10"
android:text="@string/record_time"
android:textColor="@color/VerdeApp" />
<com.yottacode.pictogram.supervisor.gui.BotonCircular
......
......@@ -50,6 +50,8 @@
<string name="version_label">Version:</string>
<string name="drawer_open">Open Menu</string>
<string name="drawer_close">Close Menu</string>
<string name="audio">Audio:</string>
<string name="record_time">mantenga pulsado</string>
</resources>
......@@ -49,6 +49,8 @@
<string name="drawer_open">Abrir Menu</string>
<string name="drawer_close">Cerrar Menu</string>
<string name="titleCropper">Nuevo Pictograma</string>
<string name="audio">Audio:</string>
<string name="record_time">mantenga pulsado</string>
</resources>
......@@ -51,5 +51,7 @@
<string name="drawer_close">Close Menu</string>
<string name="insertPasswordLogin">Inserte Contraseña</string>
<string name="version_label">Version:</string>
<string name="audio">Audio:</string>
<string name="record_time">mantenga pulsado</string>
</resources>
......@@ -31,7 +31,7 @@ public class PictoAnimation {
private final static String LOG_TAG = PictoAnimation.class.getCanonicalName();
public void animateTapeView(final VOCA activity, final int position, final ViewGroup view) {
public void animateTapeView(final VOCA activity, final int position, final ViewGroup view, final boolean uptotheend, int duration) {
final GridView gridview = (GridView) view.getChildAt(1);
final TapeAdapter tapeAdapter=(TapeAdapter)gridview.getAdapter();
......@@ -70,24 +70,26 @@ public class PictoAnimation {
public void onAnimationEnd(Animator animation) {
v.setColorFilter(0);
v.setBackgroundColor(ContextCompat.getColor(PCBcontext.getContext(), R.color.picto_default_background));
if (position < (tapeAdapter.getCount() - 1))
animateTapeView(activity,position + 1, view);
else {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (tapeAdapter.play())
tapeAdapter.endPlay();
}
});
activity.pictoMainGridAdapter.allPictosInGrid();
activity.pictoCategoryGridAdapter.allPictosInGrid();
if (position < (tapeAdapter.getCount() - 1) ) {
if (uptotheend)
animateTapeView(activity, position + 1, view, uptotheend,tapeAdapter.getItem(position+1).get_translation().length()*100);
}else {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (tapeAdapter.play())
tapeAdapter.endPlay();
}
});
activity.pictoMainGridAdapter.allPictosInGrid();
activity.pictoCategoryGridAdapter.allPictosInGrid();
}
}
@Override
public void onAnimationCancel(Animator animation) {
if (tapeAdapter.play())
tapeAdapter.endPlay();
}
@Override
......@@ -96,7 +98,7 @@ public class PictoAnimation {
}
});
colorAnim.setDuration(tapeAdapter.getItem(position).get_translation().length()*100);
colorAnim.setDuration(duration);
colorAnim.start();
}
public static int adjustAlpha(int color, float factor) {
......
......@@ -2,6 +2,9 @@ package com.yottacode.pictogram.tabletlibrary.gui.communicator;
import android.annotation.TargetApi;
import android.media.AudioAttributes;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import android.view.View;
......@@ -13,16 +16,66 @@ import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.pictogram.tts.TTSHelper;
import java.io.File;
import java.util.Iterator;
import java.util.LinkedList;
class RecordedSentencePlayer {
private static final String LOG_TAG = RecordedSentencePlayer.class.getSimpleName();
TapeAdapter tapeAdapter;
MediaPlayer mp;
public RecordedSentencePlayer(TapeAdapter tapeAdapter) {this.tapeAdapter=tapeAdapter;}
public boolean play() {
return mp==null || (mp!=null && mp.isPlaying());
}
public void playRecordedSentences(final VOCA context, final PictoAnimation pa, final ViewGroup viewGroup, final Object[] pictos, final int i) {
if (i==pictos.length) {
mp.release();
mp=null;
return;
}
Picto picto = (Picto)pictos[i];
if (mp!=null) mp.release();
mp = MediaPlayer.create(context, Uri.parse(picto.get_audioPath()));
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (viewGroup!=null) playRecordedSentences(context,pa,viewGroup,pictos,i+1);
else {
Log.e(LOG_TAG,"Error playing recorded sound at "+i+" position");
tapeAdapter.endPlay();
}
}
});
mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.e(LOG_TAG,"Error playing recorded sound, what: "+what+" extra:"+extra);
tapeAdapter.endPlay();
mp.release();
mp=null;
return false;
}
});
mp.setAudioAttributes(new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SPEECH).build() );
mp.start();
pa.animateTapeView(context, i, viewGroup,false, mp.getDuration());
}
}
public class TapeAdapter extends BaseAdapter {
private static final String LOG_TAG = TapeAdapter.class.getName();
//private Context mContext;
private LinkedList<Picto> pictoLinkedList;
private boolean play = false;
RecordedSentencePlayer recordedPlayer=new RecordedSentencePlayer(this);
public TapeAdapter() {
//mContext = c;
pictoLinkedList = new LinkedList<Picto>(); // the list begins empty
......@@ -92,11 +145,14 @@ public class TapeAdapter extends BaseAdapter {
public String getAllAsString() {
String complete = "";
Iterator<Picto> iterator = pictoLinkedList.iterator();
boolean recorded=true;
while (iterator.hasNext()) {
Picto current = iterator.next();
File recordedFile=current.get_audioFile();
recorded&=recordedFile!=null;
complete += " " + current.get_translation();
}
return complete;
return recorded ? null : complete;
}
......@@ -120,15 +176,25 @@ public class TapeAdapter extends BaseAdapter {
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void ttsAllNew(TTSHelper tts) {
public void ttsAllNew(TTSHelper tts, VOCA voca, ViewGroup viewGroup) {
this.play = true;
String input = getAllAsString();
tts.play(input);
PictoAnimation pa=new PictoAnimation();
if (input!=null) {
tts.play(input);
pa.animateTapeView(voca, 0, viewGroup,true, getItem(0).get_translation().length()*100);
}else playRecordedSentences(voca,pa,viewGroup,pictoLinkedList.toArray());
}
public boolean play() {
return this.play;
return this.play && recordedPlayer.play();
}
public void playRecordedSentences(final VOCA context, PictoAnimation pa, ViewGroup viewGroup, Object[] pictos) {
recordedPlayer.playRecordedSentences(context, pa, viewGroup, pictos, 0);
}
}
......@@ -749,7 +749,7 @@ public abstract class VOCA extends Activity implements VocabularyTalk.iVocabular
p.set_mirror(false, false);
// If the picto is a category
Log.e("VOCA",p.get_translation()+":"+p.get_id()+":"+PCBcontext.getVocabulary().is_category(p));
if (PCBcontext.getVocabulary().is_category(p)) {
currentCategory = p;
PCBcontext.getActionLog().log(new TalkAction(TalkAction.SELECT, p));
......@@ -785,7 +785,7 @@ public abstract class VOCA extends Activity implements VocabularyTalk.iVocabular
PCBcontext.getActionLog().log(new TalkAction(TalkAction.ADD, p));
if (VOCA.this.feedback_read && !VOCA.this.tapeAdapter.play() && !PCBcontext.getVocabulary().is_category(p)) {
File audioFile = p.get_audioFile();
Log.e(LOG_TAG, "AUDIO:" + (audioFile != null) + ":" + p.get_audioPath());
if (audioFile != null)
VOCA.this.tts.playRecord(audioFile);
else
......@@ -875,8 +875,7 @@ public abstract class VOCA extends Activity implements VocabularyTalk.iVocabular
// This triggers the "Show" websocket action SI hay algo en la cinta y esta no está vacia
if (lp.size() > 0 && !VOCA.this.tapeAdapter.play()) {
PCBcontext.getActionLog().log(new PictosAction(lp));
tapeAdapter.ttsAllNew(tts);
new PictoAnimation().animateTapeView(VOCA.this, 0, (ViewGroup) arg0.getParent());
tapeAdapter.ttsAllNew(tts,VOCA.this, (ViewGroup) arg0.getParent());
if (PCBcontext.getPcbdb().getCurrentUser().delivery() != User.JSON_STUDENT_ATTTRS.delivery.clean) {
showOnlyTape(true);
}
......
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