añadidi el boton de musica, bajado los botones medio cm

This commit is contained in:
Kevin Alonso
2026-05-16 02:02:11 +02:00
parent 03925e1ea8
commit 1184a53a81
4 changed files with 51 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package com.helldivers.app; package com.helldivers.app;
import android.content.Intent; import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@@ -13,7 +14,9 @@ public class MainActivity extends AppCompatActivity {
private SoundManager soundManager; private SoundManager soundManager;
private Button btnQrInstagram; private Button btnQrInstagram;
private Button btnMinijuego; private Button btnMinijuego;
private Button btnMusic;
private ImageButton btnUp, btnDown, btnLeft, btnRight; private ImageButton btnUp, btnDown, btnLeft, btnRight;
private MediaPlayer mediaPlayer;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -32,6 +35,7 @@ public class MainActivity extends AppCompatActivity {
btnDown = findViewById(R.id.btn_down); btnDown = findViewById(R.id.btn_down);
btnLeft = findViewById(R.id.btn_left); btnLeft = findViewById(R.id.btn_left);
btnRight = findViewById(R.id.btn_right); btnRight = findViewById(R.id.btn_right);
btnMusic = findViewById(R.id.btn_music);
if (btnQrInstagram != null) { if (btnQrInstagram != null) {
btnQrInstagram.setOnClickListener(v -> { btnQrInstagram.setOnClickListener(v -> {
@@ -45,6 +49,10 @@ public class MainActivity extends AppCompatActivity {
}); });
} }
if (btnMusic != null) {
btnMusic.setOnClickListener(v -> toggleMusic());
}
View.OnClickListener arrowSoundListener = v -> { View.OnClickListener arrowSoundListener = v -> {
if (soundManager != null) { if (soundManager != null) {
try { soundManager.playButtonClick(); } catch (Exception e) {} try { soundManager.playButtonClick(); } catch (Exception e) {}
@@ -57,6 +65,31 @@ public class MainActivity extends AppCompatActivity {
if (btnRight != null) btnRight.setOnClickListener(arrowSoundListener); if (btnRight != null) btnRight.setOnClickListener(arrowSoundListener);
} }
private void toggleMusic() {
if (mediaPlayer == null) {
mediaPlayer = MediaPlayer.create(this, R.raw.ost);
mediaPlayer.setOnCompletionListener(mp -> {
stopMusic();
});
}
if (mediaPlayer.isPlaying()) {
stopMusic();
} else {
mediaPlayer.start();
btnMusic.setAlpha(0.5f); // Efecto visual de activado
}
}
private void stopMusic() {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
btnMusic.setAlpha(1.0f); // Restaurar opacidad
}
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
@@ -72,6 +105,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
stopMusic();
if (soundManager != null) soundManager.release(); if (soundManager != null) soundManager.release();
} }
} }

View File

@@ -57,6 +57,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:translationY="30dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">

View File

@@ -60,6 +60,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:layout_marginTop="40dp" android:layout_marginTop="40dp"
android:translationY="30dp"
android:rowCount="3" android:rowCount="3"
android:columnCount="3" android:columnCount="3"
android:padding="8dp"> android:padding="8dp">
@@ -128,4 +129,19 @@
<!-- Footer - Versión abajo centro --> <!-- Footer - Versión abajo centro -->
<!-- Botón Música - Derecha, nivelado con el botón de la derecha -->
<Button
android:id="@+id/btn_music"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@id/buttons_grid"
android:layout_marginEnd="16dp"
android:layout_marginBottom="20dp"
android:background="@drawable/btn_helldivers_primary"
android:text="♪"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout> </RelativeLayout>

Binary file not shown.