Skip to content

Commit

Permalink
feat: added rain, waves, shore and forest sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
tara-pogancev committed Aug 23, 2022
1 parent f8d01f7 commit 423189b
Show file tree
Hide file tree
Showing 41 changed files with 2,956 additions and 179 deletions.
8 changes: 6 additions & 2 deletions DeNoise/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.tarapogancev.denoise;

import static org.junit.Assert.assertEquals;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
12 changes: 12 additions & 0 deletions DeNoise/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.DeNoiseCalmingWhiteNoise">
<activity
android:name=".player.BeachWavesPlayer"
android:exported="false" />
<activity
android:name=".player.ForestPlayer"
android:exported="false" />
<activity
android:name=".player.ShorePlayer"
android:exported="false" />
<activity
android:name=".player.RainPlayer"
android:exported="false" />
<activity
android:name=".TimerDialog"
android:exported="false" />
Expand Down
117 changes: 97 additions & 20 deletions DeNoise/app/src/main/java/com/tarapogancev/denoise/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.tarapogancev.denoise;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand All @@ -20,8 +15,17 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;

import com.tarapogancev.denoise.player.BeachWavesPlayer;
import com.tarapogancev.denoise.player.BrownNoisePlayer;
import com.tarapogancev.denoise.player.ForestPlayer;
import com.tarapogancev.denoise.player.PinkNoisePlayer;
import com.tarapogancev.denoise.player.RainPlayer;
import com.tarapogancev.denoise.player.ShorePlayer;
import com.tarapogancev.denoise.player.WhiteNoisePlayer;
import com.tarapogancev.denoise.service.MediaPlayerService;

Expand All @@ -31,7 +35,8 @@

public class MainActivity extends AppCompatActivity {

CardView settingsButton, whiteNoiseButton, pinkNoiseButton, brownNoiseButton, nextButton, previousButton, playPauseButton, cardEmail;
CardView settingsButton, cardWhite, cardPink, cardBrown, cardRain, cardWaves, cardForest,
cardShore, nextButton, previousButton, playPauseButton, cardEmail;
TextView activeSoundText, greetingText;
ImageView playPauseImage;
RelativeLayout playControls;
Expand All @@ -56,9 +61,13 @@ protected void onCreate(Bundle savedInstanceState) {
}

settingsButton = findViewById(R.id.button_settings);
whiteNoiseButton = findViewById(R.id.card_white);
pinkNoiseButton = findViewById(R.id.card_pink);
brownNoiseButton = findViewById(R.id.card_brown);
cardWhite = findViewById(R.id.card_white);
cardBrown = findViewById(R.id.card_brown);
cardPink = findViewById(R.id.card_pink);
cardRain = findViewById(R.id.card_rain);
cardWaves = findViewById(R.id.card_waves);
cardForest = findViewById(R.id.card_forest);
cardShore = findViewById(R.id.card_shore);
nextButton = findViewById(R.id.button_next);
previousButton = findViewById(R.id.button_previous);
playPauseButton = findViewById(R.id.button_playPause);
Expand All @@ -85,24 +94,52 @@ public void onClick(View view) {
}
});

whiteNoiseButton.setOnClickListener(new View.OnClickListener() {
cardWhite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectWhiteNoise();
}
});

pinkNoiseButton.setOnClickListener(new View.OnClickListener() {
cardBrown.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectBrownNoise();
}
});

cardPink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectPinkNoise();
}
});

brownNoiseButton.setOnClickListener(new View.OnClickListener() {
cardRain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectBrownNoise();
redirectRain();
}
});

cardWaves.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectWaves();
}
});

cardForest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectForest();
}
});

cardShore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectShore();
}
});

Expand Down Expand Up @@ -141,7 +178,7 @@ public void onClick(View view) {
public void onClick(View view) {
if (mediaPlayerService.getActiveSound() == 0) {
redirectWhiteNoise();
} else if (mediaPlayerService.getActiveSound() == 1) {
} else if (mediaPlayerService.getActiveSound() == 1) {
redirectPinkNoise();
} else if (mediaPlayerService.getActiveSound() == 2) {
redirectBrownNoise();
Expand Down Expand Up @@ -188,6 +225,16 @@ private void redirectWhiteNoise() {
startActivity(intent);
}

private void redirectBrownNoise() {
if (MediaPlayerService.getInstance().getActiveSound() != 2) {
mediaPlayerService.close();
mediaPlayerService.setSong(2);
mediaPlayerService.play(this);
}
Intent intent = new Intent(MainActivity.this, BrownNoisePlayer.class);
startActivity(intent);
}

private void redirectPinkNoise() {
if (MediaPlayerService.getInstance().getActiveSound() != 1) {
mediaPlayerService.close();
Expand All @@ -198,13 +245,43 @@ private void redirectPinkNoise() {
startActivity(intent);
}

private void redirectBrownNoise() {
if (MediaPlayerService.getInstance().getActiveSound() != 2) {
private void redirectRain() {
if (MediaPlayerService.getInstance().getActiveSound() != 3) {
mediaPlayerService.close();
mediaPlayerService.setSong(2);
mediaPlayerService.setSong(3);
mediaPlayerService.play(this);
}
Intent intent = new Intent(MainActivity.this, BrownNoisePlayer.class);
Intent intent = new Intent(MainActivity.this, RainPlayer.class);
startActivity(intent);
}

private void redirectWaves() {
if (MediaPlayerService.getInstance().getActiveSound() != 4) {
mediaPlayerService.close();
mediaPlayerService.setSong(4);
mediaPlayerService.play(this);
}
Intent intent = new Intent(MainActivity.this, BeachWavesPlayer.class);
startActivity(intent);
}

private void redirectForest() {
if (MediaPlayerService.getInstance().getActiveSound() != 5) {
mediaPlayerService.close();
mediaPlayerService.setSong(5);
mediaPlayerService.play(this);
}
Intent intent = new Intent(MainActivity.this, ForestPlayer.class);
startActivity(intent);
}

private void redirectShore() {
if (MediaPlayerService.getInstance().getActiveSound() != 6) {
mediaPlayerService.close();
mediaPlayerService.setSong(6);
mediaPlayerService.play(this);
}
Intent intent = new Intent(MainActivity.this, ShorePlayer.class);
startActivity(intent);
}

Expand Down Expand Up @@ -241,7 +318,7 @@ public void setupGreetingsMessage() {
}

String greeting;
int d = 100*currentTime.getHours() + currentTime.getMinutes();
int d = 100 * currentTime.getHours() + currentTime.getMinutes();

if (d <= 400 || d > 2001) {
greeting = (getString(R.string.good_night)) + name;
Expand Down Expand Up @@ -280,7 +357,7 @@ public void onReceive(Context context, Intent intent) {
@Override
protected void onDestroy() {
super.onDestroy();
if(broadcastReceiver != null) {
if (broadcastReceiver != null) {
unregisterReceiver(broadcastReceiver);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.tarapogancev.denoise;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.w3c.dom.Text;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

public class Onboarding extends AppCompatActivity {

Expand Down Expand Up @@ -42,8 +39,8 @@ public void onClick(View view) {
}
});

sliderViewPager = (ViewPager) findViewById(R.id.layout_slider);
lineIndicatorLayout = (LinearLayout) findViewById(R.id.layout_onboardingIndicators);
sliderViewPager = findViewById(R.id.layout_slider);
lineIndicatorLayout = findViewById(R.id.layout_onboardingIndicators);

onboardingPagerAdapter = new OnboardingPagerAdapter(this);
sliderViewPager.setAdapter(onboardingPagerAdapter);
Expand All @@ -56,7 +53,7 @@ public void setupIndicator(int position) {
lines = new TextView[3];
lineIndicatorLayout.removeAllViews();

for (int i = 0; i <3; i++) {
for (int i = 0; i < 3; i++) {
lines[i] = new TextView(this);
lines[i].setText("_ ");
lines[i].setTextSize(50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ public OnboardingPagerAdapter(Context context) {
this.mContext = context;
}

int images[] = {
int[] images = {
R.drawable.sleep,
R.drawable.focus,
R.drawable.relax2
};

int titles[] = {
int[] titles = {
R.string.relax,
R.string.focus,
R.string.enjoy
};

int descriptions[] = {
int[] descriptions = {
R.string.onboarding_slide_1,
R.string.onboarding_slide_2,
R.string.onboarding_slide_3
Expand All @@ -45,13 +45,13 @@ public int getCount() {

@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == (RelativeLayout) object;
return view == object;
}

@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.onboarding_slider, container, false);

ImageView image = view.findViewById(R.id.image_onboarding);
Expand Down
11 changes: 1 addition & 10 deletions DeNoise/app/src/main/java/com/tarapogancev/denoise/Settings.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
package com.tarapogancev.denoise;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;

import java.util.Locale;
import androidx.appcompat.app.AppCompatActivity;

public class Settings extends AppCompatActivity {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package com.tarapogancev.denoise;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.util.DisplayMetrics;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;

import com.tarapogancev.denoise.service.MediaPlayerService;

import java.util.Locale;

public class SettingsFragment extends PreferenceFragment {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.tarapogancev.denoise;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

public class TimerDialog extends AppCompatActivity {

@Override
Expand Down
Loading

0 comments on commit 423189b

Please sign in to comment.