Está en la página 1de 80

SEMINARIO DE

TITULACIN

DESARROLLO DE
APLICACIONES
MVILES

NOMBRE: DAMIN JAVIER MEJA GOMEZ


PROFESOR: ING. DOMINGUEZ ESCALONA RENE
SEMINARIO DE TITULACIN

fantodami@gmail.com

NDICE

Antecedentes de Android
Hola (App Inventor)
Calculadora

Calculadora (Mtodos)
Calculadora (Clases)

7
8

Mini Calculadora y Operaciones (Clases)


Calculadora (Grafica) 10
Entorno de ADT 12-18
App Hola Como Estas
App Operaciones

19-22
23-27

App Tablas de Multiplicar


App Sound Animal

28-31

32-34

App Sounds Animales

35-42

App All
App Calculadora 43-57
App calcula imc 69-72
App Tomar Foto
App supercatt

73-61
62-73

Publicar App en Google Play


Glosario

80

74-78

ANTECEDENTES DE ANDROID:
Andy Rubn llevaba desde 1989 hasta 2003 trabajando como ingeniero en
telecomunicaciones y en el mundo de los telfonos mviles en Microsoft. Su
objetivo era crear una compaa original por s mismo, y de ah sali Android Inc.,

ADQUISICION

DE ANDROID POR GOOGLE

En julio de 2005, Google adquiri Android Inc. En aquel entonces, poco se saba
de las funciones de Android Inc. fuera de que desarrollaban software para
telfonos mviles. Esto dio pie a rumores de que Google estaba planeando entrar
en el mercado de los telfonos mviles.
En Agosto de 2005, cuando Android Inc. contaba con 22 meses de vida, Google
adquiri la empresa. Andy estaba contento con esta venta, no como ocurri con
Danger Inc". De hecho Andy pasa a formar parte del equipo de Google, y es
Donde acaba como todos sabemos cmo vicepresidente de ingeniera de Google
supervisando el desarrollo de Android.
Android ya tena toda una base slida de ms de 16 aos sobre la que ya todo iba
a funcionar y comenzar el programa de maravilla de una manera muy eficaz y
prctica. A partir de aqu comienza el trabajo de google, la compaa google
piensa en formar el proyecto de una manera ms comercial y amigable para el
usuario pero an no se decidan a sacarlo en su primer Smartphone.
Pero durante estos aos Google estaba haciendo acuerdos con fabricantes de
telfonos mviles para desarrollar el primer dispositivo Android de la historia en un
Smartphone.

PRACTICA 1
Nombre de la prctica: Hola (App Inventor)
Objetivo: Conocer el entorno de App Inventor.
Instrucciones: Elaborar el diseo de una aplicacin en App Inventor.

Esta prctica se elabor en la pgina:


< http://appinventor.mit.edu/explore/ >

En donde solo realizamos el diseo de nuestra aplicacin.

PRACTICA 2
Nombre de la prctica: Calculadora (Netbeans)
Objetivo: Aprender a realizar una calculadora en Netbeans.
Instrucciones: Elaborar una calculadora sencilla en Netbeans.

En esta prctica se hizo una calculadora a base de cdigos


en el software Netbeans

Conclusin: Aprendimos como utilizar Netbeans elaborando una


aplicacin sencilla y un copo til aun as fue un buen inicio para
aprender a utilizarlo.

PRACTICA 3

Nombre de la prctica: Calculadora (mtodos)


Objetivo: Elaborar una calculadora a base de mtodos.
Instrucciones: Elaborar una calculadora sencilla utilizando ciertos
mtodos.
Aqu nosotros hicimos una calculadora, utilizando mtodos fciles para
comenzar.

Conclusin: Aprendimos a implementar ciertos mtodos, que


ayudaran a la ejecucin correcta de dicha aplicacin.

PRACTICA 4

Nombre de la prctica: Calculadora (clases)


Objetivo: Elaborar una calculadora a base de clases.
Instrucciones: Elaborar una calculadora sencilla utilizando diferentes
clases que ayudaran a la ejecucin de la calculadora.

Conclusin: Esta prctica se elabor mediante diferentes tipos de


clases.

PRACTICA 5

Nombre de la prctica: Mini Calculadora y Operaciones (clases)


Objetivo: Elaborar una calculadora a base de clases.
Instrucciones: Elaborar una calculadora sencilla utilizando diferentes
clases que ayudaran a la ejecucin de la calculadora

Conclusin: Esta calculadora se implement diferentes tipos de


codificacin.

PRACTICA 6

Nombre de la prctica: Calculadora (grafica)


Objetivo: Elaborar una calculadora que muestre su forma grfica.
Instrucciones: Elaborar una calculadora sencilla en donde se muestre
el formato de dicha calculadora como formulario.

Conclusin: Con esta prctica aprendimos como realizar la forma


grfica de una calculadora y muy simple.

PRACTICA 7
Nombre de la prctica: Entorno de ADT
Objetivo: Conocer el entorno de ADT y sus herramientas bsicas.
Instrucciones: Elaborar un video tutorial o documento en Word donde
se explique todo el entorno de ADT.

Pantalla de inicio del ADT

En el primer inicio nos solicitar la carpeta para el espacio de trabajo


(donde se guardaran nuestras app).

Se recomienda actualizar ADT

2.-Agregar un dispositivo virtual nuevo para saber si estn


correctas nuestras aplicaciones desarrolladas en nuestro software
En la pestaa "Android Virtual Device" pulsaremos en "New":

Elegiremos las caractersticas del dispositivo virtual (nombre, device,


tipo de CPU, teclado, memoria RAM, tarjeta de memoria, etc.:

Ya tendremos creado el dispositivo virtual que podremos usar para


probar nuestras aplicaciones las veces que necesitemos.

3.- Crear un nuevo proyecto

Introduciremos los datos para la nueva aplicacin Android

Indicaremos si queremos crear un icono personalizado y la activity:

Indicaremos las propiedades del icono (o el texto) y fondo de nuestra


aplicacin Android:

Si queremos que el asistente nos cree una activity inicial para nuestra
aplicacin marcaremos "Create Activity" e indicaremos el tipo
de activity (Blan Activity, Fullscreen Activity, Master/Detail Flow").

Indicaremos el nombre para la activity, el nombre del Layout

Se iniciara la aplicacin en nuestra mquina virtual

PRACTICA 8
Nombre de la prctica: App Hola Como Estas
Objetivo: Comenzar a desarrollar una aplicacin sencilla
Instrucciones: Elaborar una aplicacin de la cual nosotros al
introducir un nombre nos mostrara un mensaje el cual diga: Hola
Como estas Y el nombre introducido
Desarrollo:
Archivo .XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/hola2"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/contenedor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/titulo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Hola Como Estas"
android:textColor="#FF0000"
android:textSize="20dp"
android:textStyle="bold" />
<EditText
android:id="@+id/mensaje"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:gravity="center_horizontal"
android:hint="Introduce Nombre"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="@+id/btnmensaje"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CCCCCC"

android:gravity="center_horizontal"
android:text="Ver Mensaje"
android:textColor="#000000" />
<TextView
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:gravity="center_horizontal"
android:text=""
android:textColor="#FF0000"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="@+id/btnborrar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:gravity="center"
android:text="Borrar"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="DAMIAN JAVIER" />
</RelativeLayout>

El diseo de nuestra aplicacin queda de la siguiente manera

Archivo. Java
package example.holacomoestas;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
public class Hola extends Activity implements OnClickListener {
EditText nom;
TextView Mensaje;
Button btnver, bb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hola);
nom = (EditText) findViewById(R.id.mensaje);
btnver = (Button) findViewById(R.id.btnmensaje);
bb = (Button) findViewById(R.id.btnborrar);
Mensaje = (TextView) findViewById(R.id.msg);
btnver.setOnClickListener(this);
bb.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {

case R.id.btnborrar:
Mensaje.setText("");
break;
case R.id.btnmensaje:

if (nom.getText().equals("")) {

Toast.makeText(null, "Faltan datos",

Toast.LENGTH_SHORT);

} else {
String n = "Hola como estas \n" +
nom.getText().toString();
Mensaje.setText(n);
}
break;
}
}

Este es el cdigo que realiza lo que le indicamos. Quedando de la


siguiente manera

Conclusin: Esto fue la aplicacin que fue de mucha ayuda para


poder comenzar a utilizar ADT
Bibliografa: video aportado por el ing. Ren Domnguez Escalona
situado en YouTube
<https://www.youtube.com/watch?v=daPsvK4bckk>

PRACTICA 9
Nombre de la prctica: App Operaciones
Objetivo: Elaborar una App con operaciones sencillas.
Instrucciones: Elaborar una aplicacin que al insertar 2 nmeros
realice 4 operaciones bsicas.
Desarrollo:
Archivo .XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondo"
tools:context=".OperacionesActivity" >
<LinearLayout
android:id="@+id/contenedor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/titulo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:text="Operaciones Damian J."
android:textColor="#FF00AA"
android:textSize="20dp"
android:textStyle="bold" />
<EditText
android:id="@+id/edtNumero1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#FFFFFF"
android:gravity="center_horizontal"
android:hint="Introduce Numero 1"
android:numeric="decimal"
android:textSize="20dp"
android:textStyle="bold" />
<EditText
android:id="@+id/edtNumero2"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:layout_marginTop="20dp"
android:background="#FFFFFF"
android:gravity="center_horizontal"
android:hint="Introduce Numero 2"
android:numeric="decimal"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="@+id/btnCalcular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#CCCCCC"
android:gravity="center_horizontal"
android:text="Calcular"
android:textColor="#FF00AA" />
<Button
android:id="@+id/btnborrar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#000000"
android:gravity="center"
android:text="Borrar"
android:textColor="#FF00AA"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/txtResultado"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#FFFFFF"
android:gravity="center_horizontal"
android:text=""
android:textColor="#FF0000"
android:textSize="20dp"
android:textStyle="bold" />

</LinearLayout>

</RelativeLayout>

As mismo al ingresar todo el cdigo ya mostrado, aparecer nuestro


diseo como este.

Archivo. Java
package com.lizbeth.operaciones1;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class OperacionesActivity extends Activity implements OnClickListener {


EditText num1, num2;
TextView resultado;
Button calcular, borrar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_operaciones);
num1 = (EditText) findViewById(R.id.edtNumero1);
num2 = (EditText) findViewById(R.id.edtNumero2);
calcular = (Button) findViewById(R.id.btnCalcular);
borrar = (Button) findViewById(R.id.btnborrar);
resultado = (TextView) findViewById(R.id.txtResultado);
calcular.setOnClickListener(this);
borrar.setOnClickListener(this);

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnCalcular:
double a = Double.parseDouble(num1.getText().toString());
double b = Double.parseDouble(num2.getText().toString());
double suma = a + b;
double resta = a - b;
double multi = a * b;
double division = a / b;

resultado.setText("Los Numeros son: " + a + " y " + b


+ "\n-------------------\n La suma es:" + suma
+ "\n-------------------\n La resta es:" + resta
+ "\n-------------------\n La multiplicacion es:" + multi
+ "\n-------------------\n La division es:" + division
+ "Fin..... :D");
break;

case R.id.btnborrar:
resultado.setText("");

num1.setText("");
num2.setText("");

break;
}
}
}

Al ejecutar nuestra aplicacin quedara como se muestra en la imagen.

Conclusin: Esta aplicacin fue sencilla ya que se utilizaron mtodos


fciles de emplear, y que no tiene un alto nivel de dificultad.

Bibliografa: video aportado por el ing. Ren Domnguez Escalona


situado en YouTube
<https://www.youtube.com/watch?v=Mx7pbPYPiQg>

PRACTICA 10
Nombre de la prctica: App Tablas de multiplicar
Objetivo: Elaborar una aplicacin que nos muestre la tabla de
multiplicar de dicho nmero.
Instrucciones: Elaborar una aplicacin de la cual insertemos un
nmero y de dicho numero aparezca su tabla de multiplicar.
Desarrollo:
Archivo .XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/descarga"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/contenedor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/titulo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center_horizontal"
android:text="Tabla de Multiplicar"
android:textColor="#FF0000"
android:textSize="17dp"
android:textStyle="bold" />
<EditText
android:id="@+id/edtNumero1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#FFFFFF"
android:gravity="center_horizontal"
android:hint="Introduce Numero"
android:numeric="decimal"
android:textSize="25dp"
android:textStyle="bold" />
<Button
android:id="@+id/btnVer"

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#CCCCCC"
android:gravity="center_horizontal"
android:text="Calcular"
android:textColor="#000000" />
<Button
android:id="@+id/btnborrar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#000000"
android:gravity="center"
android:text="Borrar"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/txtResultado"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#FFFFFF"
android:gravity="center_horizontal"
android:text=""
android:textColor="#FF0000"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>

Al momento de ingresar todo este cdigo nos mostrara nuestro diseo


de la aplicacin el cual se ver as:

Y para hacer que funcione se ingresara el siguiente cdigo:


Archivo. Java
package example.tablasdemultiplicar;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
public class MainActivity extends Activity implements OnClickListener {
EditText numero;
TextView Tabla;
Button ver, borrar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
numero = (EditText) findViewById(R.id.edtNumero1);
Tabla = (TextView) findViewById(R.id.txtResultado);
ver = (Button) findViewById(R.id.btnVer);
borrar = (Button) findViewById(R.id.btnborrar);
ver.setOnClickListener(this);
borrar.setOnClickListener(this);
}
@Override
public void onClick(View a) {
switch (a.getId()) {
case R.id.btnVer:
String res = "";
double
Double.parseDouble(numero.getText().toString());

for (int i = 1; i < 10; i++) {


res = res + " " + n + "

" + i + " = " + (i * n) + "\n";

}
Tabla.setText(res);
break;
case R.id.btnborrar:
Tabla.setText("");
numero.setText("");
break;
}
}
}

Al momento de haber ingresado correctamente dicho cdigo ahora si


probaremos nuestra aplicacin.

Y as es como queda nuestra aplicacin.

Conclusin: Con dicha aplicacin aprendimos diferentes mtodos


para hacer que funcione nuestra aplicacin, pero a su vez volvimos a
retomar ciertos cdigos que se utilizaron en aplicaciones anteriores
que fueron de gran ayuda.

PRACTICA 11
Nombre de la prctica: App SoundAnimal
Objetivo: Elaborar una aplicacin que nos reproduzca el sonido de un
animal.
Instrucciones: Elaborar una aplicacin de la cual al momento de
presionar la imagen de dicho animal reproduzca el sonido.
Desarrollo:
Archivo .XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/leon"
android:text="" />
</RelativeLayout>

Con este cdigo nosotros convertimos la imagen del animal en botn


ya que al presionarla nos reproducir su sonido de este.
Entonces nuestro diseo se vera asi:

Despus de esto comenzaremos a ingresar el


cdigo correcto para que as pueda ejecutarse y
reproducirnos dicho sonido.Archivo. Java
package example.soundleon;

import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import android.app.Activity;
import android.view.Menu;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener {


SoundPool sp;
Button il;
int a;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
il = (Button) findViewById(R.id.button1);
il.setOnClickListener(this);
sp = new SoundPool(8, AudioManager.STREAM_MUSIC, 0);
a = sp.load(this, R.raw.sleon, 1);

@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
sp.play(a, 1, 1, 1, 0, 1);
break ;

Este sera el cdigo, solo que variara en el nombre del sonido, esta
vez mi sonido se llama: len, pero va dependiendo del nombre del
archivo.

Aqu solo se mostrara nuestro diseo ya que al probarla solo


reproducir el sonido.

Conclusin: Aprendimos como implementar un archivo de audio


para que se reproduzca al tocar la imagen.

PRACTICA 12
Nombre de la prctica: App SoundsAnimales
Objetivo: Elaborar una aplicacin que nos reproduzca 9 diferentes
sonidos de animales
Instrucciones: Elaborar una aplicacin de la cual reproduzca 9
sonidos de animales diferentes.
Desarrollo:
Archivo .XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/caballo"
android:gravity="center" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/cerdo"
android:gravity="center" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/delfin"
android:gravity="center" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/gato"
android:gravity="center" />
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/leon1"
android:gravity="center" />
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/oso"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/perro"
android:gravity="center" />
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/gallo"
android:gravity="center" />

<Button
android:id="@+id/button9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/vaca2"
android:gravity="center" />
</LinearLayout>
</LinearLayout>

Con todo este cdigo lo que haces es insertar


todos los archivos de audio y de igual forma las
imgenes de cada animal
Se crea una carpeta en Res llamndola raw
en esta carpeta nosotros tendremos que
insertar todos los archivos de audio de nuestros
animales.
De igual forma se insertan las imgenes que se
ocuparan con los sonidos de los animales.

Archivo .XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/caballo"
android:gravity="center" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/cerdo"
android:gravity="center" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/delfin"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/gato"
android:gravity="center" />

<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/leon1"
android:gravity="center" />
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/oso"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/perro"
android:gravity="center" />
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/gallo"
android:gravity="center" />
<Button
android:id="@+id/button9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/vaca2"
android:gravity="center" />
</LinearLayout>
</LinearLayout>

Al insertar todo el cdigo, se mostrara nuestro


diseo de la aplicacin.

Archivo. Java
package example.soundsanimales;
import
import
import
import
import
import
import

android.media.AudioManager;
android.media.SoundPool;
android.os.Bundle;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.app.Activity;

public class Animales extends Activity implements OnClickListener {


SoundPool sp;
Button b1, b2, b3, b4, b5, b6, b7, b8, b9;
int vb1, vb2, vb3, vb4, vb5, vb6, vb7, vb8, vb9;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animales);
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
b3 = (Button) findViewById(R.id.button3);
b4 = (Button) findViewById(R.id.button4);
b5 = (Button) findViewById(R.id.button5);
b6 = (Button) findViewById(R.id.button6);
b7 = (Button) findViewById(R.id.button7);
b8 = (Button) findViewById(R.id.button8);
b9 = (Button) findViewById(R.id.button9);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
b4.setOnClickListener(this);
b5.setOnClickListener(this);
b6.setOnClickListener(this);

b7.setOnClickListener(this);
b8.setOnClickListener(this);
b9.setOnClickListener(this);
sp = new SoundPool(8, AudioManager.STREAM_MUSIC, 0);
vb1 = sp.load(this, R.raw.caballoson, 1);
vb2 = sp.load(this, R.raw.cerdoson, 1);
vb3 = sp.load(this, R.raw.delfinson, 1);
vb4 = sp.load(this, R.raw.gatoson, 1);
vb5 = sp.load(this, R.raw.leonson, 1);
vb6 = sp.load(this, R.raw.ososon, 1);
vb7 = sp.load(this, R.raw.perroson, 1);
vb8 = sp.load(this, R.raw.galloson, 1);
vb9 = sp.load(this, R.raw.vacason, 1);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
sp.play(vb1, 1, 1,
break;
case R.id.button2:
sp.play(vb2, 1, 1,
break;
case R.id.button3:
sp.play(vb3, 1, 1,
break;
case R.id.button4:
sp.play(vb4, 1, 1,
break;
case R.id.button5:
sp.play(vb5, 1, 1,
break;
case R.id.button6:
sp.play(vb6, 1, 1,
break;
case R.id.button7:
sp.play(vb7, 1, 1,
break;
case R.id.button8:
sp.play(vb8, 1, 1,
break;
case R.id.button9:
sp.play(vb9, 1, 1,
break;
}
}
}

1, 0, 1);
1, 0, 1);
1, 0, 1);
1, 0, 1);
1, 0, 1);
1, 0, 1);
1, 0, 1);
1, 0, 1);
1, 0, 1);

Despus de haber ingresado el cdigo correspondiente, para que


nuestra aplicacin funcione, ahora si se podr ejecutar dicha
aplicacin.

Conclusin:
Aqu aprendimos como insertar diferentes imgenes y sonidos y a su
vez acomodarlas de forma que no se amontonen.

PRACTICA 14
Nombre de la prctica: App Calculadora
Objetivo: Elaborar una aplicacin en donde enlacemos todas las
aplicaciones ya elaboradas.
Instrucciones: Elaborar una aplicacin en donde aparezca un men
en el cual lleve a las aplicaciones elaboradas.
Desarrollo:
Archivo .XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fon"
android:orientation="vertical"
tools:context=".Calculadora" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:background="#000000"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".25"
android:background="#000000"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/anterior"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".25"
android:background="#000000"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:text=""
android:textAlignment="textStart"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<TextView

android:id="@+id/num"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".25"
android:background="#000000"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:text=""
android:textAlignment="viewStart"
android:textColor="#FFFFFF"
android:textSize="30sp" />
</LinearLayout>
<Button
android:id="@+id/back"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/re"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:background="#000000"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/siete"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/siete"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/ocho"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/ocho"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />

<Button
android:id="@+id/nueve"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/nueve"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/mas"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/mas"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/borrar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/borrar"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:background="#000000"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/cuatro"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/cuatro"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/cinco"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:layout_weight="1"
android:gravity="center"
android:text="@string/cinco"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/seis"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/seis"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/menos"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/menos"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnraiz"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/raiz"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:background="#000000"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/uno"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/uno"
android:textColor="#FFFFFF"

android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/dos"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/dos"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/tres"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/tres"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/por"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/por"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnfactorial"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/fac"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:background="#000000"
android:gravity="center"
android:orientation="horizontal" >
<Button

android:id="@+id/cero"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/cero"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/punto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/punto"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnpi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/pi"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/entre"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/entre"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnporciento"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/porciento"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"

android:layout_height="match_parent"
android:layout_weight="0.85"
android:background="#000000"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/btnunosobrex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/unosobrex"
android:textColor="#FFFFFF"
android:textSize="40sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnelevado"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/elevado"
android:textColor="#FFFFFF"
android:textSize="40sp"
android:textStyle="bold" />
<Button
android:id="@+id/igual"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/igual"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>

Este es nuestro cdigo para el diseo de nuestra calculadora el cual


se ver as:

Archivo .Java
package example.calculadora;
import
import
import
import
import
import
import

android.app.Activity;
android.os.Bundle;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.TextView;
android.widget.Toast;

public class Calculadora extends Activity implements OnClickListener {


TextView display, anterior;
float resultado = 0, num1 = 0, num2 = 0;
int o = 0;
boolean p = false, igual = false;
Button mas, menos, por, entre, raiz, factorial, pi, XY, modulo, unoentre;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calculadora);
display = (TextView) findViewById(R.id.num);
anterior = (TextView) findViewById(R.id.anterior);
Button uno = (Button) findViewById(R.id.uno);
Button dos = (Button) findViewById(R.id.dos);
Button tres = (Button) findViewById(R.id.tres);
Button cuatro = (Button) findViewById(R.id.cuatro);
Button cinco = (Button) findViewById(R.id.cinco);
Button seis = (Button) findViewById(R.id.seis);
Button siete = (Button) findViewById(R.id.siete);

Button ocho = (Button) findViewById(R.id.ocho);


Button nueve = (Button) findViewById(R.id.nueve);
Button cero = (Button) findViewById(R.id.cero);
Button punto = (Button) findViewById(R.id.punto);
mas = (Button) findViewById(R.id.mas);
menos = (Button) findViewById(R.id.menos);
por = (Button) findViewById(R.id.por);
entre = (Button) findViewById(R.id.entre);
raiz = (Button) findViewById(R.id.btnraiz);
factorial = (Button) findViewById(R.id.btnfactorial);
Button borrar = (Button) findViewById(R.id.borrar);
Button igual = (Button) findViewById(R.id.igual);
Button back = (Button) findViewById(R.id.back);
pi = (Button) findViewById(R.id.btnpi);
XY = (Button) findViewById(R.id.btnelevado);
unoentre = (Button) findViewById(R.id.btnunosobrex);
modulo = (Button) findViewById(R.id.btnporciento);

uno.setOnClickListener(this);
dos.setOnClickListener(this);
tres.setOnClickListener(this);
cuatro.setOnClickListener(this);
cinco.setOnClickListener(this);
seis.setOnClickListener(this);
siete.setOnClickListener(this);
ocho.setOnClickListener(this);
nueve.setOnClickListener(this);
mas.setOnClickListener(this);
menos.setOnClickListener(this);
por.setOnClickListener(this);
entre.setOnClickListener(this);
cero.setOnClickListener(this);
igual.setOnClickListener(this);
punto.setOnClickListener(this);
raiz.setOnClickListener(this);
factorial.setOnClickListener(this);
borrar.setOnClickListener(this);
igual.setOnClickListener(this);
back.setOnClickListener(this);
pi.setOnClickListener(this);
XY.setOnClickListener(this);
unoentre.setOnClickListener(this);
modulo.setOnClickListener(this);

public void deshabilitar() {


mas.setEnabled(false);
menos.setEnabled(false);
por.setEnabled(false);
entre.setEnabled(false);
raiz.setEnabled(false);
factorial.setEnabled(false);
unoentre.setEnabled(false);
pi.setEnabled(false);
XY.setEnabled(false);

modulo.setEnabled(false);

public void habilitar() {


mas.setEnabled(true);
menos.setEnabled(true);
por.setEnabled(true);
entre.setEnabled(true);
raiz.setEnabled(true);
factorial.setEnabled(true);
unoentre.setEnabled(true);
pi.setEnabled(true);
XY.setEnabled(true);
modulo.setEnabled(true);
}
public boolean validar() {
if (display.getText().equals("")) {
Toast m = Toast.makeText(this, "falta introducir numero",
Toast.LENGTH_SHORT);
m.show();
return false;
} else {
if (o == 0) {
num1 = Float.parseFloat(display.getText().toString());
} else {
num2 = Float.parseFloat(display.getText().toString());
}
return true;
}
}
public void borrar() {
display.setText("");
anterior.setText("");
resultado = 0;
num1 = 0;
num2 = 0;
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnelevado:
if (igual == true) {
resultado = num1;
igual = false;
} else {
resultado = 0;
}
if (validar() == true) {
anterior.setText(num1 + "^");
display.setText("");
o = 1;
p = false;
deshabilitar();

case

case

case

case

}
break;
R.id.btnporciento:
if (igual == true) {
resultado = num1;
igual = false;
} else {
resultado = 0;
}
if (validar() == true) {
anterior.setText(num1 + "%");
display.setText("");
o = 2;
p = false;
deshabilitar();
}
break;
R.id.mas:
if (validar() == true) {
if (igual == true) {
resultado = num1;
igual = false;
} else {
resultado = 0;
}
anterior.setText(num1 + "+");
display.setText("");
o = 3;
p = false;
deshabilitar();
}
break;
R.id.menos:
if (igual == true) {
resultado = num1;
igual = false;
} else {
resultado = 0;
}
if (validar() == true) {
anterior.setText(num1 + "-");
display.setText("");
o = 4;
p = false;
deshabilitar();
}
break;
R.id.por:
if (igual == true) {
resultado = num1;
igual = false;
} else {
resultado = 0;
}
if (validar() == true) {

anterior.setText(num1 + "*");
display.setText("");
o = 5;
p = false;
deshabilitar();

case

case

case

case

case

case

}
break;
R.id.entre:
if (igual == true) {
resultado = num1;
igual = false;
} else {
resultado = 0;
}
if (validar() == true) {
anterior.setText(num1 + "/");
display.setText("");
o = 6;
p = false;
deshabilitar();
}
break;
R.id.btnunosobrex:
if (validar() == true) {
anterior.setText("1/" + num1);
resultado = 1 / num1;
display.setText("" + resultado);
o = 0;
}
break;
R.id.btnraiz:
if (validar() == true) {
anterior.setText("" + num1);
resultado = (float) Math.sqrt(num1);
display.setText("" + resultado);
o = 0;
}
break;
R.id.btnfactorial:
if (validar() == true) {
anterior.setText(num1 + "!");
resultado = factorial(num1);
display.setText("" + resultado);
o = 0;
}
break;
R.id.uno:
if (igual == true) {
borrar();
igual = false;
}
display.append("1");
break;
R.id.dos:
if (igual == true) {

borrar();
igual = false;

case

case

case

case

case

case

case

case

}
display.append("2");
break;
R.id.tres:
if (igual == true) {
borrar();
igual = false;
}
display.append("3");
break;
R.id.cuatro:
if (igual == true) {
borrar();
igual = false;
}
display.append("4");
break;
R.id.cinco:
if (igual == true) {
borrar();
igual = false;
}
display.append("5");
break;
R.id.seis:
if (igual == true) {
borrar();
igual = false;
}
display.append("6");
break;
R.id.siete:
if (igual == true) {
borrar();
igual = false;
}
display.append("7");
break;
R.id.ocho:
if (igual == true) {
borrar();
igual = false;
}
display.append("8");
break;
R.id.nueve:
if (igual == true) {
borrar();
igual = false;
}
display.append("9");
break;
R.id.cero:

case

case

case

case

case

if (igual == true) {
borrar();
igual = false;
}
display.append("0");
break;
R.id.punto:
if (p == false && igual == false) {
display.append(".");
p = true;
} else {
borrar();
display.append(".");
p = false;
igual = false;
}
break;
R.id.borrar:
borrar();
habilitar();
break;
R.id.back:
String cad = display.getText().toString();
if (!cad.equals("")) {
char[] cadena = cad.toCharArray();
String f = "";
for (int i = 0; i <= cadena.length - 2; i++) {
f = f + cadena[i];
}
display.setText(f);
} else {
Toast m = Toast.makeText(this, "No hay valores",
Toast.LENGTH_SHORT);
m.show();
resultado = 0;
habilitar();
}
break;
R.id.btnpi:
resultado = (float) 3.1416;
display.setText("3.1416");
break;
R.id.igual:
if (validar() == true) {
switch (o) {
case 1:
resultado = (float) Math.pow(num1, num2);
break;
case 2:
resultado = num1 % num2;
break;
case 3:
resultado = num1 + num2;
break;
case 4:

resultado = num1 - num2;


break;
case 5:
resultado = num1 * num2;
break;
case 6:
resultado = num1 / num2;
break;
}

}
o = 0;
p = false;
num1 = resultado;
igual = true;
habilitar();
anterior.append("" + num2);
display.setText("" + redondear(resultado));
break;
}

public float factorial(float numero) {


float fac = 1;
for (int i = 1; i <= numero; i++) {
fac *= 1;
}
return fac;
}
public float redondear(float numero) {
return (float) Math.rint(numero * 100000) / 100000;
}
}

Conclusin:
Aqu se vio como es que se ingresan diferentes datos y frmulas para
llevar a cabo la ejecucin correcta de nuestra calculadora con
diferentes operaciones.

PRACTICA 17
Nombre de la prctica: App supercatt
Objetivo: Aprender a elaborar un juego bsico como es el de gato.
Instrucciones: Elaborar el juego mediante cdigos, que lo que
realizara ser que el Smartphone Y el Usuario puedan ganar.
Desarrollo:
Archivo .XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondo"
android:orientation="vertical"
tools:context=".MainGato" >
<Button
android:id="@+id/bt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="20dp"
android:background="@drawable/botonro"
android:gravity="center"
android:text="Un Jugador"
android:textColor="#FFFFFF"
android:textSize="35dp"
android:textStyle="bold" />
<Button
android:id="@+id/bt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="@drawable/botonro"
android:gravity="center"
android:text="2 Jugadores"
android:textColor="#FFFFFF"
android:textSize="35dp"
android:textStyle="bold" />
<Button
android:id="@+id/acercade"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="@drawable/botonro"

android:gravity="center"
android:text="Acerca de"
android:textColor="#FFFFFF"
android:textSize="35sp"
android:textStyle="bold" />
<Button
android:id="@+id/salir"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="@drawable/botonro"
android:gravity="center"
android:text="Salir"
android:textColor="#FFFFFF"
android:textSize="35sp"
android:textStyle="bold" />
</LinearLayout>

Unjugador.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:background="@drawable/fila"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="@+id/uno"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15sp"
android:layout_weight="1" />
<ImageView
android:id="@+id/dos"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15sp"
android:layout_weight="1" />
<ImageView

android:id="@+id/tres"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15sp"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:background="@drawable/fila"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="@+id/cuatro"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15sp"
android:layout_weight="1" />
<ImageView
android:id="@+id/cinco"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15sp"
android:layout_weight="1" />
<ImageView
android:id="@+id/seis"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15sp"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85"
android:background="@drawable/fila"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="@+id/siete"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15sp"
android:layout_weight="1" />
<ImageView
android:id="@+id/ocho"
android:layout_width="match_parent"

android:layout_height="match_parent"
android:layout_margin="15sp"
android:layout_weight="1" />
<ImageView
android:id="@+id/nueve"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15sp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>

El archivo .Java ser este.


package com.lizbeth.tresenraya;
import
import
import
import
import
import
import

android.os.Bundle;
android.os.Handler;
android.view.View;
android.view.View.OnClickListener;
android.widget.ImageView;
android.widget.Toast;
android.app.Activity;

public class UnJugador extends Activity implements OnClickListener {


int[] gato = new int[9];
boolean ganaUsuario = false, ganaSmartPhone = false;
int aleatorio;
ImageView uno, dos, tres, cuatro, cinco, seis, siete, ocho, nueve;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.unjugador);
uno = (ImageView) findViewById(R.id.uno);
dos = (ImageView) findViewById(R.id.dos);
tres = (ImageView) findViewById(R.id.tres);
cuatro = (ImageView) findViewById(R.id.cuatro);
cinco = (ImageView) findViewById(R.id.cinco);
seis = (ImageView) findViewById(R.id.seis);
siete = (ImageView) findViewById(R.id.siete);
ocho = (ImageView) findViewById(R.id.ocho);
nueve = (ImageView) findViewById(R.id.nueve);
uno.setOnClickListener(this);
dos.setOnClickListener(this);
tres.setOnClickListener(this);
cuatro.setOnClickListener(this);
cinco.setOnClickListener(this);
seis.setOnClickListener(this);
siete.setOnClickListener(this);
ocho.setOnClickListener(this);

nueve.setOnClickListener(this);
for (int i = 0; i <= 0; i++) {
gato[i] = 0;
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.uno:
if (gato[0] == 0) {
uno.setImageResource(R.drawable.tom);
gato[0] = 1;
ChecarSiGana();
TeTocaSmartPhone();
}
break;
case R.id.dos:
if (gato[1] == 0) {
dos.setImageResource(R.drawable.tom);
gato[1] = 1;
ChecarSiGana();
TeTocaSmartPhone();
}
break;
case R.id.tres:
if (gato[2] == 0) {
tres.setImageResource(R.drawable.tom);
gato[2] = 1;
ChecarSiGana();
TeTocaSmartPhone();
}
break;
case R.id.cuatro:
if (gato[3] == 0) {
cuatro.setImageResource(R.drawable.tom);
gato[3] = 1;
ChecarSiGana();
TeTocaSmartPhone();
}
break;
case R.id.cinco:
if (gato[4] == 0) {
cinco.setImageResource(R.drawable.tom);
gato[4] = 1;
ChecarSiGana();
TeTocaSmartPhone();
}
break;
case R.id.seis:
if (gato[5] == 0) {
seis.setImageResource(R.drawable.tom);

ChecarSiGana();
gato[5] = 1;
TeTocaSmartPhone();

}
break;
case R.id.siete:
if (gato[6] == 0) {
siete.setImageResource(R.drawable.tom);
ChecarSiGana();
gato[6] = 1;
TeTocaSmartPhone();
}
break;
case R.id.ocho:
if (gato[7] == 0) {
ocho.setImageResource(R.drawable.tom);
ChecarSiGana();
gato[7] = 1;
TeTocaSmartPhone();
}
break;
case R.id.nueve:
if (gato[8] == 0) {
nueve.setImageResource(R.drawable.tom);
ChecarSiGana();
gato[8] = 1;
TeTocaSmartPhone();
}
break;
}
}
public void TeTocaSmartPhone() {
if (ganaUsuario == false) {
aleatorio = (int) (8 * Math.random()) + 1;
if (gato[aleatorio] == 0) {
switch (aleatorio) {
case 0:
uno.setImageResource(R.drawable.jerry);
break;
case 1:
dos.setImageResource(R.drawable.jerry);
break;
case 2:
tres.setImageResource(R.drawable.jerry);
break;
case 3:
cuatro.setImageResource(R.drawable.jerry);
break;
case 4:
cinco.setImageResource(R.drawable.jerry);
break;
case 5:
seis.setImageResource(R.drawable.jerry);

break;
case 6:
siete.setImageResource(R.drawable.jerry);
break;
case 7:
ocho.setImageResource(R.drawable.jerry);
break;
case 8:
nueve.setImageResource(R.drawable.jerry);
break;
}
gato[aleatorio] = 2;
ChecarSiGana();
} else {
TeTocaSmartPhone();
}
}
}
public void ChecarSiGana() {
if (gato[0] == 1 && gato[1] == 1 && gato[2] == 1)
ganaUsuario = true;
if (gato[3] == 1 && gato[4] == 1 && gato[5] == 1)
ganaUsuario = true;
if (gato[6] == 1 && gato[7] == 1 && gato[8] == 1)
ganaUsuario = true;
if (gato[0] == 1 && gato[3] == 1 && gato[6] == 1)
ganaUsuario = true;
if (gato[1] == 1 && gato[4] == 1 && gato[7] == 1)
ganaUsuario = true;
if (gato[2] == 1 && gato[5] == 1 && gato[8] == 1)
ganaUsuario = true;
if (gato[0] == 1 && gato[4] == 1 && gato[8] == 1)
ganaUsuario = true;
if (gato[2] == 1 && gato[4] == 1 && gato[6] == 1)
ganaUsuario = true;
if (ganaUsuario == true) {
Toast m = Toast.makeText(this, "Ganaste Suertudote",
Toast.LENGTH_SHORT);
m.show();
borrar();
}
if (gato[0] == 2 && gato[1] == 2
ganaSmartPhone = true;
if (gato[3] == 2 && gato[4] == 2
ganaSmartPhone = true;
if (gato[6] == 2 && gato[7] == 2
ganaSmartPhone = true;
if (gato[0] == 2 && gato[3] == 2
ganaSmartPhone = true;
if (gato[1] == 2 && gato[4] == 2
ganaSmartPhone = true;
if (gato[2] == 2 && gato[5] == 2

&& gato[2] == 2)
&& gato[5] == 2)
&& gato[8] == 2)
&& gato[6] == 2)
&& gato[7] == 2)
&& gato[8] == 2)

ganaSmartPhone = true;
if (gato[0] == 2 && gato[4] == 2 && gato[8] == 2)
ganaSmartPhone = true;
if (gato[2] == 2 && gato[4] == 2 && gato[6] == 2)
ganaSmartPhone = true;
if (ganaSmartPhone == true) {
Toast m = Toast.makeText(this, "Te Gano el Super SmartPhone",
Toast.LENGTH_SHORT);
m.show();
borrar();
}
}
private void borrar() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
uno.setImageDrawable(null);
dos.setImageDrawable(null);
tres.setImageDrawable(null);
cuatro.setImageDrawable(null);
cinco.setImageDrawable(null);
seis.setImageDrawable(null);
siete.setImageDrawable(null);
ocho.setImageDrawable(null);
nueve.setImageDrawable(null);
ganaUsuario = false;
ganaSmartPhone = false;
for (int i = 0; i <= 0; i++) {
gato[i] = 0;
}
}
}, 2000);
}
}

Acercade.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondol"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainGato" >

<LinearLayout
android:layout_width="295dp"
android:layout_height="296dp"
android:background="@drawable/damian"
android:gravity="center"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>

AcercaDe.Java
package com.damian.tresenraya;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class AcercaDe extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acercade);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

Tambin se debe de modificar el archivo AndroidManifest.XML para


que toda la aplicacin en general pueda acceder a los dems botones.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lizbeth.tresenraya"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.lizbeth.tresenraya.MainGato"

android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.lizbeth.tresenraya.AcercaDe"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.lizbeth.tresenraya.DosJugadores"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.lizbeth.tresenraya.UnJugador"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Con todo este cdigo nuestra aplicacin funcionara.


Conclusin: Se aprendi como realizar un simple juego en Android, a
base de diferentes tipos de cdigos para hacer que dicha aplicacin
funcione utilizando lo antes visto.

PRACTICA 16
Nombre de la prctica: calcularimc
Objetivo: Aprender a desaroyar una aplicacin con los conocimientos
aprendidos
Instrucciones: sesarrollar una app
Desarrollo:

cdigo XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fon"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="peso en (kg)" />
<EditText
android:id="@+id/etPeso"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etPeso"
android:layout_below="@+id/etPeso"
android:text="Altura en (cm)" />
<EditText

android:id="@+id/etAltura"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:ems="10"
android:inputType="number" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etAltura"
android:layout_below="@+id/etAltura"
android:text="Calcular" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:text="Resultado IMC"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/tvResultado"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_alignRight="@+id/textView3"
android:layout_below="@+id/textView3"
android:text=" "
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>

Nos queda la app de la siguiente manera

codigo java
package example.calcularimc;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
float p, a, imc;
EditText peso, altura;
Button calcular;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
peso = (EditText) findViewById(R.id.etPeso);
altura = (EditText) findViewById(R.id.etAltura);
calcular = (Button) findViewById(R.id.button1);
calcular.setOnClickListener(this);
}

@Override
public void onClick(View v) {
if (v.getId() == R.id.button1) {
p = Float.parseFloat(peso.getText().toString());
a = Float.parseFloat(altura.getText().toString()) / 100;
if (a != 0) {
float resultado = p / (a * a);
TextView tvResultado = (TextView)
findViewById(R.id.tvResultado);
tvResultado.setText("" + resultado);
} else {
Toast.makeText(this, "introdusca altura valida",
Toast.LENGTH_LONG);
}
}
}
}
Conclucion: aprendimos a desaroyar una aplicacin muy til de forma
autnoma aplicando los conocimientos que nos dieron en clase

PRACTICA 18
Nombre de la prctica: Publicar App en Google Play
Objetivo: Aprender como publicar nuestra aplicacin en Google Play
Instrucciones: seguir los pasos para publicar nuestra aplicacin en
Google Play
Desarrollo:
Paso 1
Le damos clic en aadir nueva aplicacin

Asignaremos un nombre a nuestra app

cargaremos nuestra app

buscaremos nuestra aplicacin a subir

esperaremos a
nuestra app

que cargue

llenaremo cada uno de los campos requeridos para publicar nuestra aplicacin

pondremos las capturaas del telefono es un requerimiento

pondremos el logotipo de nuestra app

Conclusin: pudimos aprender a subir una aplicacin en play store fue


muy fcil y aplicamos los conocimientos aprendidos en clase.
Se subi la aplicacin a
DEVELOPER CONSOLE.

Glosario de palabras:
ADT: Android Developers tolos
APP: Aplicacin
ANDROID: Sistema Operativo para SmartPhone
APP INVENTOR: Pagina para elaborar Aplicaciones.
NETBEANS: entorno de desarrollo integrado
principalmente para el lenguaje de programacin Java

libre,

hecho

También podría gustarte