Está en la página 1de 15

Angel Ricardo Spraud Ureña

2020-10621
Introducción al desarrollo de
aplicaciones móviles
Tarea movil
Tarea movil
Una aplicación que me muestre un spinner con 5 tipos de comida si
selecciono uno me mande a una lista de 5 tipos de comida con una foto
que generalice esas comidas.
Al dar clic en el tipo de comida me mande a una ventana con una lista de
al menos 4 comidas que entre en ese tipo de comidas usando listview,
debe aparecer mínimo la imagen de la comida, nombre y una breve
descripción.
Al dar clic en una comida me muestre en una ventana la imagen, nombre,
tipo de comida, la receta en sí y un botón de compartir la comida.
• Usar algún tipo de array para los datos.

Ejemplo si tengo desayuno en el tipo de comida, me aparezca en la


lista tipos de desayunos, luego al dar clic me manda la otra
información de ese desayuno seleccionado.

Codigo fuente:
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF"
tools:context=".MainActivity">
<View
android:background="#273036"
android:layout_width="match_parent"
android:layout_height="80dp"/>
<ImageView
android:layout_width="match_parent"
3
android:layout_height="60dp"
android:background="@drawable/wave"/>
<TextView
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/negro"
android:textSize="27sp"
android:text="@string/mainTitulo"/>
<Spinner
android:layout_marginTop="5dp"
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="80dp"/>
<ImageView
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_width="300dp"
android:layout_height="300dp"
android:src="@drawable/cook"/>
</LinearLayout>
Adapter_view_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
4
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="150dp"
android:layout_height="150dp" />
<TextView
android:id="@+id/titulo"
android:layout_marginLeft="2dp"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/negro"
android:fontFamily="serif-monospace"
android:textSize="28dp"/>
</LinearLayout>
</LinearLayout>
Detalles_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<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">
<ImageButton
android:id="@+id/detalleBack"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp"
android:layout_width="100px"
5
android:layout_height="100px"
android:src="@drawable/back"
android:background="#273036"
android:elevation="2dp"/>
<View
android:id="@+id/background"
android:background="#273036"
android:layout_width="match_parent"
android:layout_height="80dp"/>
<ImageView
android:layout_below="@+id/background"
android:id="@+id/wave"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/wave"/>
<LinearLayout
android:layout_below="@id/wave"
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/detallesImg"
android:layout_width="300px"
android:layout_height="300px"/>
<TextView
android:layout_marginLeft="10px"
android:id="@+id/detalleTitulo"
android:layout_width="wrap_content"
6
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/negro"
android:fontFamily="serif-monospace"
android:textSize="30sp"/>
</LinearLayout>
<RelativeLayout
android:id="@+id/detalle"
android:layout_marginTop="10px"
android:layout_below="@id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/detalleTipo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/negro"
android:fontFamily="serif-monospace"
android:textSize="20sp"/>
<ImageButton
android:id="@+id/share"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:background="#FFFFFF"
android:src="@drawable/share" />
</RelativeLayout>
<ScrollView
7
android:layout_below="@id/detalle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_marginBottom="10px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ed1c25"
android:fontFamily="serif-monospace"
android:text="Ingredientes"
android:textColor="#ffffff"
android:textSize="30sp" />
<TextView
android:id="@+id/ingredientes"
android:layout_marginTop="10px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/negro"
android:textSize="20sp"
android:fontFamily="serif-monospace"/>
<TextView
android:layout_marginBottom="10px"
android:background="#ed1c25"
android:layout_width="wrap_content"
8
android:layout_height="wrap_content"
android:text="Receta"
android:textColor="#ffffff"
android:textSize="30sp"
android:fontFamily="serif-monospace"/>
<TextView
android:id="@+id/detallesReceta"
android:layout_marginTop="10px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/negro"
android:textSize="20sp"
android:fontFamily="serif-monospace"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Recetas.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/recetasBack"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp"
android:layout_width="100px"
android:layout_height="100px"
android:src="@drawable/back"
9
android:background="#273036"
android:elevation="2dp"/>
<View
android:id="@+id/recetaBackground"
android:background="#273036"
android:layout_width="match_parent"
android:layout_height="80dp"/>
<ImageView
android:layout_below="@+id/recetaBackground"
android:id="@+id/recetaWave"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/wave"/>
<LinearLayout
android:layout_below="@+id/recetaWave"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_marginTop="5dp"
android:id="@+id/recetasTitulo"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="27sp"
android:textColor="@color/negro"
android:text="Recetas de hamburguesas"/>
<ListView
android:id="@+id/listView"
10
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
Código
Detalles.java
package com.example.spinner;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class Detalles extends AppCompatActivity implements
ImageView.OnClickListener{
String tipo;
Receta receta;
ImageView detallesImg;
TextView detalleTitulo;
TextView detalleTipo;
TextView ingredientes;
TextView detallesReceta;
ImageButton back, share;
protected void onCreate(Bundle savedInstance){
super.onCreate(savedInstance);
setContentView(R.layout.detalles_layout);
11
Bundle bundle = getIntent().getExtras();
tipo = bundle.getString("tipo");
receta = (Receta) bundle.getSerializable("data");
back = findViewById(R.id.detalleBack);
share = findViewById(R.id.share);
detallesImg = findViewById(R.id.detallesImg);
detalleTipo = findViewById(R.id.detalleTipo);
detalleTitulo = findViewById(R.id.detalleTitulo);
ingredientes = findViewById(R.id.ingredientes);
detallesReceta = findViewById(R.id.detallesReceta);
detallesImg.setImageResource(receta.getImg());
detalleTipo.setText(tipo);
detalleTitulo.setText(receta.getTitulo());
ingredientes.setText(receta.getIngrediente());
detallesReceta.setText(receta.getReceta());
back.setOnClickListener(this);
share.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String datos = "Nombre de la comida: " +
detalleTitulo.getText().toString() +
"\n" + "Tipo de comida: " +
detalleTipo.getText().toString();
switch(v.getId()){
case R.id.detalleBack:
this.finish();
break;
case R.id.share:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
12
intent.putExtra(Intent.EXTRA_TEXT, datos);
intent.setType("text/plain");
if(intent.resolveActivity(getPackageManager()) != null)
startActivity(Intent.createChooser(intent, "Compartir con:
"));
break;
}
}
}
MainActivity.java
package com.example.spinner;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
implements
AdapterView.OnItemSelectedListener {
Spinner spinner;
String comida;
int currentPosition = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner = findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(this,
13
R.array.food_array,
android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View
view, int
position, long
id) {
comida = parent.getItemAtPosition(position).toString();
if(currentPosition == position){
return;
}
else{
Intent intent = new Intent(this, Recetas.class);
Bundle var = new Bundle();
var.putString("comida", comida);
intent.putExtras(var);
startActivity(intent);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
Receta.java
package com.example.spinner;
import java.io.Serializable;
public class Receta implements Serializable {
private String titulo;
14
private int img;
private String ingrediente;
private String receta;
public Receta(String[] informacion, int img){
this.titulo = informacion[0];
this.ingrediente = informacion[1];
this.receta = informacion[2];
this.img = img;
}
public String getTitulo() {
return titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public int getImg() {
return img;
}
public void setImg(int img) {
this.img = img;
}
public String getIngrediente() {
return ingrediente;
}
public void setIngrediente(String ingrediente) {
this.ingrediente = ingrediente;
}
public String getReceta() {
return receta;
15
}
public void setReceta(String receta) {
this.receta = receta;
}
}
RecetaListAdapter.java
package com.example.spinner;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class RecetaListAdapter extends
ArrayAdapter<Receta> {
private Context mContext;
private ArrayList<Receta> recetas;
int mResource;
public RecetaListAdapter(Context context, int resource,
ArrayList<Receta>
objects) {
super(context, resource, objects);
this.recetas = objects;
mContext = context;
mResource = resource;
}
16
@NonNull
@Override
public View getView(int position, @Nullable View
convertView,
@NonNull ViewGroup
parent) {
String[] informacion = new String[3];
informacion[0] = getItem(position).getTitulo();
informacion[1] = getItem(position).getIngrediente();
informacion[2] = getItem(position).getReceta();
int img = getItem(position).getImg();
Receta receta = new Receta(informacion, img);
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(mResource, parent, false);
TextView titulo = convertView.findViewById(R.id.titulo);
ImageView imageView =
convertView.findViewById(R.id.image);
titulo.setText(informacion[0]);
imageView.setImageResource(img);
return convertView;
}
}
Recetas.java
package com.example.spinner;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
17
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.io.Serializable;
import java.util.ArrayList;
public class Recetas extends AppCompatActivity implements
AdapterView.OnItemClickListener, ImageView.OnClickListener
{
ArrayList<Receta> comidaList;
/*
ArrayList<Receta> bizcochoList;
ArrayList<Receta> pizzaList;
ArrayList<Receta> lasañaList;
ArrayList<Receta> pechugaList;
*/
String tipo;
Resources res;
ListView listView;
Intent intent;
ImageButton back;
protected void onCreate(Bundle savedInstance){
super.onCreate(savedInstance);
setContentView(R.layout.recetas);
res = getResources();
listView = findViewById(R.id.listView);
back = findViewById(R.id.recetasBack);
Bundle bundle = getIntent().getExtras();
tipo = bundle.getString("comida");
comidaList = new ArrayList<>();
if(tipo.equals("Hamburguesa")){
comidaList.add(new
Receta(res.getStringArray(R.array.hAguacate),
18
R.drawable.hamburguesa_aguacate));
comidaList.add(new
Receta(res.getStringArray(R.array.hFiletePescado),
R.drawable.hamburguesa_filete_de_pescado));
comidaList.add(new
Receta(res.getStringArray(R.array.hArabe),
R.drawable.hamburguesa_arabe));
comidaList.add(new
Receta(res.getStringArray(R.array.hCangrejo),
R.drawable.hamburguesa_de_cangrejo));
comidaList.add(new
Receta(res.getStringArray(R.array.hMini),
R.drawable.mini_hamburguesas));
}
if(tipo.equals("Pizza")){
comidaList.add(new
Receta(res.getStringArray(R.array.pAtun),
R.drawable.pizza_atun_aceitunas_negras));
comidaList.add(new
Receta(res.getStringArray(R.array.pCalabazaChile),
R.drawable.pizza_de_calabaza));
comidaList.add(new
Receta(res.getStringArray(R.array.pDip),
R.drawable.pizza_dip_salchicha_italiana));
comidaList.add(new
Receta(res.getStringArray(R.array.pMexicana),
R.drawable.receta_de_pizza_mexicana_de_flor_de_calabaza));
comidaList.add(new
Receta(res.getStringArray(R.array.pPepperoni),
R.drawable.pizza_peperoni_fantasmas));
}
if(tipo.equals("Bizcocho")){
comidaList.add(new
Receta(res.getStringArray(R.array.bBorracho),
R.drawable.bizcocho_borracho));
comidaList.add(new
Receta(res.getStringArray(R.array.bCocoFresa),
R.drawable.cassata_de_coco_y_fresa));
19
comidaList.add(new
Receta(res.getStringArray(R.array.bFrances),
R.drawable.bizcocho_frances_de_ciruela));
comidaList.add(new
Receta(res.getStringArray(R.array.bMacarronesDulces),
R.drawable.macarrones_dulces));
comidaList.add(new
Receta(res.getStringArray(R.array.bNuez),
R.drawable.bizcocho_con_nuez));
}
if(tipo.equals("Lasaña")){
comidaList.add(new
Receta(res.getStringArray(R.array.lconBolasDeCarne),
R.drawable.lasana_bolitas_de_carne));
comidaList.add(new
Receta(res.getStringArray(R.array.lSinCarne),
R.drawable.lasana_calabacitas_y_cebolla));
comidaList.add(new
Receta(res.getStringArray(R.array.lCamarones),
R.drawable.lasana_camarones));
comidaList.add(new
Receta(res.getStringArray(R.array.lAguacate),
R.drawable.lasana_de_aguacate));
comidaList.add(new
Receta(res.getStringArray(R.array.lVegetariana),
R.drawable.lasana_de_calabaza));
}
if(tipo.equals("Pechuga de pollo")){
comidaList.add(new
Receta(res.getStringArray(R.array.pParrilla),
R.drawable.pechuga_a_a_parilla));
comidaList.add(new
Receta(res.getStringArray(R.array.pEscalfadas),
R.drawable.pechugas_escalfadas_rellenas_queso));
comidaList.add(new
Receta(res.getStringArray(R.array.pPavo),
R.drawable.pechuga_pavo_ostizada));
20
comidaList.add(new
Receta(res.getStringArray(R.array.pEnsaladaPechuga),
R.drawable.ensalada_verdolagas_pollo));
comidaList.add(new
Receta(res.getStringArray(R.array.pRellenasPollo),
R.drawable.lasana_de_calabaza));
}
RecetaListAdapter adapter = new RecetaListAdapter(this,
R.layout.adapter_view_layout, comidaList);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
back.setOnClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view,
int
position, long id)
{
Bundle var = new Bundle();
Receta data = comidaList.get(position);
intent = new Intent(this, Detalles.class);
var.putString("tipo", tipo);
var.putSerializable("data", data);
intent.putExtras(var);
startActivity(intent);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.recetasBack:
21
this.finish();
}
}
}

También podría gustarte