Skip to content

Commit

Permalink
feat(reset level and music): music added and functionality to reset l…
Browse files Browse the repository at this point in the history
…evel added
  • Loading branch information
jcrucesdeveloper committed Mar 4, 2023
1 parent 69ed9f7 commit a197834
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
}

@Override
protected void onResume() {
super.onResume();

}

public void goToLinesMenuActivity(View view) {
Intent intent = new Intent(this, MenuMetroActivity.class);
startActivity(intent);
Expand Down Expand Up @@ -100,9 +106,6 @@ public void showConfirmationResetDialog(View view) {
dialog.dismiss();
});




// Reset Shared Preferences
dialog.show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import android.content.res.Resources;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
Expand Down Expand Up @@ -133,6 +135,7 @@ private void setLineName() {
throw new Error("Hubo un problema al iniciar el level");
}
this.lineName = extra.getString("LINEA");
Log.d("LINE NAME", this.lineName);
}

/**
Expand Down Expand Up @@ -301,6 +304,12 @@ public void onWinLevel() {
this.showWinningDialog();
}

private void resetLevel() {
Intent intent = new Intent(this.getApplicationContext(), PlayGameActivity.class);
intent.putExtra("LINEA", this.lineName);
this.startActivity(intent);
}

private void updateProgressInfo() {

SharedPreferences sharedPref = this.getSharedPreferences(
Expand All @@ -323,6 +332,8 @@ private void updateProgressInfo() {
private void showWinningDialog() {
// Show dialog
Dialog winningDialog = new Dialog(this);
winningDialog.setCancelable(false);
winningDialog.setCanceledOnTouchOutside(false);
winningDialog.setContentView(R.layout.winning_dialog);

// Button
Expand All @@ -335,9 +346,25 @@ private void showWinningDialog() {
winningDialog.show();
}


private void onIncorrectAlternative() {
Toast.makeText(this, "INCORRECTO", Toast.LENGTH_SHORT).show();
//TODO - add ads
this.onLostLevel();
}

private void onLostLevel() {
// TODO - Ads
Dialog lostDialog = new Dialog(this);
lostDialog.setCancelable(false);
lostDialog.setCanceledOnTouchOutside(false);
lostDialog.setContentView(R.layout.lost_dialog);

ImageView resetLevelImageView = (ImageView) lostDialog.findViewById(R.id.imageViewResetLevel);

resetLevelImageView.setOnClickListener(listener-> {
this.resetLevel();
});

lostDialog.show();
}

public void goBackToMenu(View view) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
package com.jorgecruces.metrometro.logic;

import android.os.Build;
import android.util.Log;

import androidx.annotation.RequiresApi;

import com.jorgecruces.metrometro.logger.LoggerSout;
import com.jorgecruces.metrometro.model.Station;

import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.atomic.AtomicReferenceArray;

public class PickerStationsAlternative {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,49 @@
package com.jorgecruces.metrometro.sound;

import android.content.Context;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.os.Build;
import android.provider.MediaStore;
import android.util.Log;

import com.jorgecruces.metrometro.R;

import java.io.IOException;

/**
* Singleton that reproduce the sound across the App
* Singleton class that works as a general Audio Manager
*/
public class MediaPlayerReproducer {

private static final MediaPlayerReproducer mp = new MediaPlayerReproducer();
private MediaPlayer mediaPlayer;

private boolean isAudioReproducing = true;
private boolean isMusicOn = true;

/**
Singleton Pattern
*/
private MediaPlayerReproducer()
{
}

public static MediaPlayerReproducer getInstance()
{
return mp;
}

/**
* Change between reproduce Sound
*/

// Audio and Music Setting
public void changeAudioReproducing() {
isAudioReproducing = !isAudioReproducing;
}

/**
* Change between reproduce Music
*/
public void changeMusicReproducing() {
isMusicOn = !isMusicOn;
}

public boolean getAudioBoolean() {
return this.isAudioReproducing;
}

public boolean getMusicBoolean() {
return this.isMusicOn;
}

public static MediaPlayerReproducer getInstance()
{
return mp;
}

/**
* Reproduce click Sound
Expand All @@ -72,9 +63,17 @@ public void reproduceWinSound(Context context)
reproduceSound(context, R.raw.win_sound);
}

public void reproduceMusic(Context context) {
public void reproduceMusicMainMenu(Context context) {
if (!isMusicOn) {return;}
// this.mediaPlayer = MediaPlayer.create(context, R.raw.);
// this.mediaPlayer.setLooping(true);
// this.mediaPlayer.start();
}

public void stopMusicMainMenu() {
if (this.mediaPlayer != null) {
this.mediaPlayer.stop();
}
}

/**
Expand Down
Binary file added app/src/main/res/drawable/gameplay_button_ad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions app/src/main/res/layout/configuration_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:padding="5dp">

<TextView
android:id="@+id/nextLevelTextView"
android:id="@+id/lostTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
Expand Down Expand Up @@ -51,7 +51,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nextLevelTextView" />
app:layout_constraintTop_toBottomOf="@+id/lostTextView" />

<ImageView
android:id="@+id/goBackButtonConfiguration"
Expand All @@ -60,7 +60,7 @@
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toStartOf="@+id/nextLevelTextView"
app:layout_constraintEnd_toStartOf="@+id/lostTextView"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/confirmation_reset_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:background="@color/white">

<TextView
android:id="@+id/nextLevelTextView"
android:id="@+id/lostTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/titiliumweb_bold"
Expand Down Expand Up @@ -60,7 +60,7 @@
app:layout_constraintBottom_toTopOf="@+id/buttonGoBackConfirmationDialog"
app:layout_constraintEnd_toStartOf="@+id/buttonResetConfirmationDialog"
app:layout_constraintStart_toEndOf="@+id/buttonGoBackConfirmationDialog"
app:layout_constraintTop_toBottomOf="@+id/nextLevelTextView"
app:layout_constraintTop_toBottomOf="@+id/lostTextView"
app:srcCompat="@drawable/confirmation_dialog" />

</androidx.constraintlayout.widget.ConstraintLayout>
79 changes: 79 additions & 0 deletions app/src/main/res/layout/lost_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/dialogLayout"
android:layout_width="match_parent"
android:layout_height="230dp"
android:background="@color/white">

<TextView
android:id="@+id/lostTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="@font/titiliumweb_bold"
android:padding="20dp"
android:text="¡Acabas de perder! :("
android:textAlignment="center"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/imageViewResetLevel"
android:layout_width="101dp"
android:layout_height="84dp"
android:layout_marginStart="64dp"
android:layout_marginEnd="60dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/imageView10"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/main_menu_button_reset" />

<ImageView
android:id="@+id/imageView10"
android:layout_width="101dp"
android:layout_height="84dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="64dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageViewResetLevel"
app:srcCompat="@drawable/gameplay_button_ad" />

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_marginEnd="8dp"
android:fontFamily="@font/titiliumweb_bold"
android:text="Continuar"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/imageView10"
app:layout_constraintEnd_toEndOf="@+id/imageView10"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:fontFamily="@font/titiliumweb_bold"
android:text="Reiniciar nivel"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/imageViewResetLevel"
app:layout_constraintStart_toStartOf="@+id/imageViewResetLevel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/winning_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:background="@color/white">

<TextView
android:id="@+id/nextLevelTextView"
android:id="@+id/lostTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
Expand Down Expand Up @@ -44,7 +44,7 @@
app:layout_constraintBottom_toTopOf="@+id/buttonResetConfirmationDialog"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nextLevelTextView"
app:layout_constraintTop_toBottomOf="@+id/lostTextView"
app:srcCompat="@drawable/lines_metro_star" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit a197834

Please sign in to comment.