0% found this document useful (0 votes)
2 views15 pages

Tarea Tema 2

The document presents a mobile development project by participant Josué Ricardo Hernández Montero, focusing on an Android application layout and functionality. It includes XML layout code for a user interface that features a color gradient control, input fields, and swipe gesture detection for specific actions. The Java code implements the application's logic, including calculating currency denominations based on user input and responding to swipe gestures for clearing input or exiting the app.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views15 pages

Tarea Tema 2

The document presents a mobile development project by participant Josué Ricardo Hernández Montero, focusing on an Android application layout and functionality. It includes XML layout code for a user interface that features a color gradient control, input fields, and swipe gesture detection for specific actions. The Java code implements the application's logic, including calculating currency denominations based on user input and responding to swipe gestures for clearing input or exiting the app.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PRESENTACIÓN.

Participante:

Josué Ricardo Hernández Montero - 2024-0235

Fecha: 30/01/20256

Asignatura:

Introduccion al desarrollo mobile

Docente:

Freidy Nunez Perez




<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="[Link]

android:id="@+id/layoutPrincipal"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="16dp"

android:background="@android:color/white">

<!-- Zona de control de color degradado -->

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:padding="12dp"

android:background="#E0E0E0"

android:layout_marginBottom="16dp">

<TextView

android:id="@+id/tvColorInfo"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Degradado: Gris → Gris"

android:textAlignment="center"

android:textSize="14sp"

android:textStyle="bold"

android:textColor="#333333"

android:layout_marginBottom="8dp"/>

<SeekBar
android:id="@+id/seekBarColor"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:max="100"

android:progress="50"/>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:layout_marginTop="4dp">

<TextView

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text=" ⬛ Negro"
android:textSize="12sp"

android:textColor="#333333"/>

<TextView

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Blanco ⬜"
android:textSize="12sp"

android:textAlignment="textEnd"

android:textColor="#333333"/>

</LinearLayout>

</LinearLayout>
<ImageView

android:id="@+id/ivLogo"

android:layout_width="120dp"

android:layout_height="120dp"

android:layout_gravity="center"

android:src="@drawable/logo_institucion"

android:contentDescription="Logo de la institución"

android:layout_marginBottom="24dp"/>

<EditText

android:id="@+id/etCantidad"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Ingrese la cantidad (use el teclado del dispositivo)"

android:inputType="number"

android:textSize="18sp"

android:padding="12dp"

android:background="@drawable/edittext_border"

android:layout_marginBottom="16dp"/>

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Presione el botón de VOLUMEN ARRIBA para calcular"

android:textAlignment="center"

android:textSize="14sp"

android:textStyle="bold"

android:textColor="#2196F3"

android:padding="8dp"
android:background="#E3F2FD"

android:layout_marginBottom="16dp"/>

<TextView

android:id="@+id/tvResultado"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1"

android:textSize="16sp"

android:textColor="#000000"

android:padding="12dp"

android:background="@drawable/texview_border"

android:layout_marginBottom="16dp"/>

<View

android:layout_width="match_parent"

android:layout_height="3dp"

android:background="#FF9800"

android:layout_marginBottom="8dp"/>

<TextView

android:id="@+id/tvInstruccionesSwipe"

android:layout_width="match_parent"

android:layout_height="wrap_content"

👈
android:text="⬇ ZONA DE SWIPE (Mitad inferior) ⬇ \n\n
Izquierda → Derecha: SALIR\n
👉
Swipe Derecha → Izquierda: LIMPIAR"
Swipe

android:textAlignment="center"

android:textSize="14sp"

android:textStyle="bold"

android:textColor="#FF5722"
android:padding="16dp"

android:background="#FFEBEE"/>

</LinearLayout>

package [Link].homework2;

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class MainActivity extends Activity {

private EditText etCantidad;

private TextView tvResultado;

private TextView tvInstruccionesSwipe;

private ImageView ivLogo;

private LinearLayout layoutPrincipal;

private SeekBar seekBarColor;


private TextView tvColorInfo;

private GestureDetectorCompat gestureDetector;

private static final int SWIPE_THRESHOLD = 100;

private static final int SWIPE_VELOCITY_THRESHOLD = 100;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

etCantidad = findViewById([Link]);

tvResultado = findViewById([Link]);

tvInstruccionesSwipe = findViewById([Link]);

ivLogo = findViewById([Link]);

layoutPrincipal = findViewById([Link]);

seekBarColor = findViewById([Link]);

tvColorInfo = findViewById([Link]);

gestureDetector = new GestureDetectorCompat(this, new


SwipeGestureListener());

setupColorSeekBar();

[Link](new [Link]() {

@Override

public boolean onKey(View v, int keyCode, KeyEvent event) {

return false;

});
[Link]();

private void setupColorSeekBar() {

[Link](100);

[Link](50); // Empezar en el medio (gris)

[Link](new
[Link]() {

@Override

public void onProgressChanged(SeekBar seekBar, int progress,


boolean fromUser) {

aplicarDegradado(progress);

@Override

public void onStartTrackingTouch(SeekBar seekBar) {}

@Override

public void onStopTrackingTouch(SeekBar seekBar) {}

});

// Aplicar degradado inicial

aplicarDegradado(50);

private void aplicarDegradado(int progress) {

int colorArriba, colorAbajo;


if (progress < 50) {

float factor = progress / 50f;

int grisArriba = (int)(factor * 128);

int grisAbajo = 255 - (int)((1 - factor) * 127);

colorArriba = [Link](grisArriba, grisArriba, grisArriba);

colorAbajo = [Link](grisAbajo, grisAbajo, grisAbajo);

} else {

float factor = (progress - 50) / 50f;

int grisArriba = 128 + (int)(factor * 127);

int grisAbajo = 128 - (int)(factor * 128);

colorArriba = [Link](grisArriba, grisArriba, grisArriba);

colorAbajo = [Link](grisAbajo, grisAbajo, grisAbajo);

GradientDrawable gradiente = new GradientDrawable(

[Link].TOP_BOTTOM,

new int[]{colorArriba, colorAbajo}

);

[Link](gradiente);

// Actualizar texto informativo

if (progress < 25) {

[Link]("Degradado: Negro → Gris oscuro");

} else if (progress < 50) {

[Link]("Degradado: Gris oscuro → Gris");

} else if (progress < 75) {

[Link]("Degradado: Gris → Gris claro");


} else {

[Link]("Degradado: Gris claro → Blanco");

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {

calcularBilletes();

return true; // Consumir el evento para que no suba el volumen

return [Link](keyCode, event);

private void calcularBilletes() {

String cantidadStr = [Link]().toString().trim();

if ([Link]()) {

[Link]("Por favor, ingrese una cantidad");

return;

try {

int cantidad = [Link](cantidadStr);

if (cantidad < 0) {

[Link]("La cantidad debe ser positiva");

return;

}
// Calcular billetes y monedas

int billetes100 = cantidad / 100;

int resto = cantidad % 100;

int billetes50 = resto / 50;

resto = resto % 50;

int billetes20 = resto / 20;

resto = resto % 20;

int monedas10 = resto / 10;

resto = resto % 10;

int monedas5 = resto / 5;

resto = resto % 5;

// Mostrar resultado

StringBuilder resultado = new StringBuilder();

[Link]("Desglose de
$").append(cantidad).append(":\n\n");

if (billetes100 > 0) {

[Link]("
").append(billetes100).append("\n");
💵 Billetes de $100:

if (billetes50 > 0) {

[Link]("
").append(billetes50).append("\n");
💵 Billetes de $50:

if (billetes20 > 0) {

[Link]("
").append(billetes20).append("\n");
💵 Billetes de $20:
}

if (monedas10 > 0) {

").append(monedas10).append("\n");
[Link]("🪙 Monedas de $10:

if (monedas5 > 0) {

").append(monedas5).append("\n");
[Link](" 🪙 Monedas de $5:

if (resto > 0) {

[Link]("\n ⚠️ Sobrante: $").append(resto);


}

[Link]([Link]());

} catch (NumberFormatException e) {

[Link]("Por favor, ingrese un número válido");

@Override

public boolean onTouchEvent(MotionEvent event) {

[Link](event);

return [Link](event);

@Override

public boolean dispatchTouchEvent(MotionEvent event) {

[Link](event);

return [Link](event);

}
private class SwipeGestureListener extends
[Link] {

@Override

public boolean onFling(MotionEvent e1, MotionEvent e2, float


velocityX, float velocityY) {

if (e1 == null || e2 == null) {

return false;

float diffX = [Link]() - [Link]();

float diffY = [Link]() - [Link]();

if ([Link](diffX) > [Link](diffY)) {

if ([Link](diffX) > SWIPE_THRESHOLD && [Link](velocityX)


> SWIPE_VELOCITY_THRESHOLD) {

int screenHeight = [Link]();

float touchY = [Link]();

if (touchY > screenHeight / 2) {

if (diffX > 0) {

onSwipeIzquierdaDerecha();

} else {

onSwipeDerechaIzquierda();

return true;

}
}

return false;

@Override

public boolean onDown(MotionEvent e) {

return true;

private void onSwipeIzquierdaDerecha() {

finish();

private void onSwipeDerechaIzquierda() {

[Link]("");

[Link]("");

[Link]();

You might also like