forked from dangilcal/Helldivers-app-movil
añadidi el boton de musica, bajado los botones medio cm
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.helldivers.app;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
@@ -13,7 +14,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
private SoundManager soundManager;
|
||||
private Button btnQrInstagram;
|
||||
private Button btnMinijuego;
|
||||
private Button btnMusic;
|
||||
private ImageButton btnUp, btnDown, btnLeft, btnRight;
|
||||
private MediaPlayer mediaPlayer;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -32,6 +35,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
btnDown = findViewById(R.id.btn_down);
|
||||
btnLeft = findViewById(R.id.btn_left);
|
||||
btnRight = findViewById(R.id.btn_right);
|
||||
btnMusic = findViewById(R.id.btn_music);
|
||||
|
||||
if (btnQrInstagram != null) {
|
||||
btnQrInstagram.setOnClickListener(v -> {
|
||||
@@ -45,6 +49,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
if (btnMusic != null) {
|
||||
btnMusic.setOnClickListener(v -> toggleMusic());
|
||||
}
|
||||
|
||||
View.OnClickListener arrowSoundListener = v -> {
|
||||
if (soundManager != null) {
|
||||
try { soundManager.playButtonClick(); } catch (Exception e) {}
|
||||
@@ -57,6 +65,31 @@ public class MainActivity extends AppCompatActivity {
|
||||
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
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
@@ -72,6 +105,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
stopMusic();
|
||||
if (soundManager != null) soundManager.release();
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:translationY="30dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_marginTop="40dp"
|
||||
android:translationY="30dp"
|
||||
android:rowCount="3"
|
||||
android:columnCount="3"
|
||||
android:padding="8dp">
|
||||
@@ -128,4 +129,19 @@
|
||||
|
||||
<!-- 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>
|
||||
BIN
app/src/main/res/raw/ost.mp3
Normal file
BIN
app/src/main/res/raw/ost.mp3
Normal file
Binary file not shown.
Reference in New Issue
Block a user