App inventor 2 en español
Cómo programar los teléfonos móviles con Android.
Curso de App inventor 2 en español - Juan Antonio Villalpando
-- Tutorial de iniciación de App Inventor 2 en español --
Volver al índice del tutorial
_________________________________________________
116.- Java Bridge. Cámara. Reproductor de sonido. Sonido. Reconocimiento de Voz. Yandex.
- Cámara: hace la foto pero luego no retorna la imagen.
- Reproductor de sonido. Funciona. Recuerda que tienes que poner el archivo de sonido en la carpeta assets.
- Sonido corto. Funciona. Recuerda que tienes que poner el archivo de sonido en la carpeta assets.
- Reconocimiento de Voz. Funciona.
- Traductor Yandex. No funciona.
- Grabador de voz. No funciona.
- En algunas líneas he tenido que agregar el código manualmente, ya que no se crean automáticamente.
_____________________________________________________
Medios.aia
_____________________________________________________
- Diseño.
_____________________________________________________
- Bloques.
_____________________________________________________
- Conversion a Java.
- Pulsamos en "Generate Java"
- Pulsamos en JAVA FILE.
Screen1.java |
package juan.com.camara; // Cambia por tu package.
import com.google.appinventor.components.runtime.HandlesEventDispatching;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.Form;
import com.google.appinventor.components.runtime.Component;
import com.google.appinventor.components.runtime.Button;
import com.google.appinventor.components.runtime.Image;
import com.google.appinventor.components.runtime.Label;
import com.google.appinventor.components.runtime.Camera;
import com.google.appinventor.components.runtime.Player;
import com.google.appinventor.components.runtime.Sound;
import com.google.appinventor.components.runtime.SpeechRecognizer;
import com.google.appinventor.components.runtime.YandexTranslate;
class Screen1 extends Form implements HandlesEventDispatching {
private Button Boton1;
private Image Imagen1;
private Button Boton2;
private Button Boton3;
private Button Boton4;
private Button Boton5;
private Label Etiqueta1;
private Label Etiqueta2;
private Camera Camara1;
private Player Reproductor1;
private Sound Sonido1;
private SpeechRecognizer ReconocimientoDeVoz1;
private YandexTranslate TraductorYandex1;
protected void $define() {
this.AppName("Medios");
this.Title("Screen1");
Boton1 = new Button(this);
Boton1.Width(LENGTH_FILL_PARENT);
Boton1.Text("Camara de foto e Imagen.");
Imagen1 = new Image(this);
Boton2 = new Button(this);
Boton2.Width(LENGTH_FILL_PARENT);
Boton2.Text("Reproductor de Sonido");
Boton3 = new Button(this);
Boton3.Width(LENGTH_FILL_PARENT);
Boton3.Text("Sonido corto");
Boton4 = new Button(this);
Boton4.Width(LENGTH_FILL_PARENT);
Boton4.Text("Reconocimiento de voz");
Boton5 = new Button(this);
Boton5.Width(LENGTH_FILL_PARENT);
Boton5.Text("Traductor Yandex");
Etiqueta1 = new Label(this);
Etiqueta1.Text("Texto para Etiqueta1");
Etiqueta2 = new Label(this);
Etiqueta2.Text("Texto para Etiqueta2");
Camara1 = new Camera(this);
Reproductor1 = new Player(this);
Sonido1 = new Sound(this);
ReconocimientoDeVoz1 = new SpeechRecognizer(this);
TraductorYandex1 = new YandexTranslate(this);
EventDispatcher.registerEventForDelegation(this, "ClickEvent", "Click" );
EventDispatcher.registerEventForDelegation(this, "AfterPictureEvent", "AfterPicture" );
EventDispatcher.registerEventForDelegation(this, "AfterGettingTextEvent", "AfterGettingText" );
EventDispatcher.registerEventForDelegation(this, "GotTranslationEvent", "GotTranslation" );
}
public boolean dispatchEvent(Component component, String componentName, String eventName, Object[] params){
if( component.equals(Boton1) && eventName.equals("Click") ){
Boton1Click();
return true;
}
if( component.equals(Camara1) && eventName.equals("AfterPicture") ){
Camara1AfterPicture((String)params[0]);
return true;
}
if( component.equals(Boton2) && eventName.equals("Click") ){
Boton2Click();
return true;
}
if( component.equals(Boton3) && eventName.equals("Click") ){
Boton3Click();
return true;
}
if( component.equals(Boton4) && eventName.equals("Click") ){
Boton4Click();
return true;
}
if( component.equals(ReconocimientoDeVoz1) && eventName.equals("AfterGettingText") ){
ReconocimientoDeVoz1AfterGettingText((String)params[0]);
return true;
}
if( component.equals(Boton5) && eventName.equals("Click") ){
Boton5Click();
return true;
}
if( component.equals(TraductorYandex1) && eventName.equals("GotTranslation") ){
TraductorYandex1GotTranslation((String)params[0], (String)params[1]);
return true;
}
return false;
}
public void Boton1Click(){
Camara1.TakePicture(); // Manual
}
public void Camara1AfterPicture(String imagen){
Imagen1.Picture(imagen);
}
public void Boton2Click(){
Reproductor1.Source("pajarito.mp3");
Reproductor1.Start();
}
public void Boton3Click(){
Sonido1.Source("beep8.mp3");
Sonido1.Play(); // Manual
}
public void Boton4Click(){
ReconocimientoDeVoz1.GetText(); // Manual
}
public void ReconocimientoDeVoz1AfterGettingText(String Resultado){
Etiqueta1.Text(Resultado);
}
public void Boton5Click(){
TraductorYandex1.RequestTranslation("es-en", "Esto es un ejemplo.");
}
public void TraductorYandex1GotTranslation(String codigoDeRespuesta, String traduccion){
Etiqueta2.Text(traduccion);
}
}
|
_____________________________________________________
__________________________________
|