Commit 2798f077 authored by Trevor Slocum's avatar Trevor Slocum

Add session volume preview

Resolves #52
parent 3168f28f
1.5.9:
- Add resources menu linking to how to meditate, /r/meditation, an overview of MediNET and replaying the tutorial
- Add presets to tutorial
- Add session volume preview
- Resolve possible crash when waking device
- Resolve duration not being preselected when editing
- Remove usage of Google Play Services (was previously used in releases on Google Play and Amazon)
......
......@@ -220,11 +220,11 @@ public class ListPreferenceSound extends ListPreference {
afd.getDeclaredLength());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setUsage(AudioAttributes.USAGE_ALARM)
.build();
mMediaPlayer.setAudioAttributes(audioAttributes);
} else {
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
}
mMediaPlayer.setVolume(mediaVolume, mediaVolume);
mMediaPlayer.prepareAsync();
......
......@@ -476,6 +476,11 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
} else if (item.getItemId() == R.id.action_reddit_community) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://old.reddit.com/r/meditation")).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
} else if (item.getItemId() == R.id.action_replay_tutorial) {
if (sv != null) {
sv.hide();
sv = null;
}
next_tutorial = "";
finishedTutorial = null;
getMeditationAssistant().getPrefs().edit().putBoolean("finishedTutorial", false).apply();
showNextTutorial(true);
......
......@@ -2,6 +2,11 @@ package sh.ftp.rocketninelabs.meditationassistant;
import android.app.AlertDialog;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.preference.DialogPreference;
import android.util.AttributeSet;
......@@ -12,6 +17,8 @@ import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import java.io.IOException;
public class SeekBarPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener, OnClickListener {
// ------------------------------------------------------------------------------------------
// Private attributes :
......@@ -21,6 +28,8 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
private TextView mSplashText, txtHelp, mValueText;
private Context mContext;
private MediaPlayer mediaPlayer;
private String mDialogMessage, mSuffix;
private int mDefault, mMax, mValue = 0;
// ------------------------------------------------------------------------------------------
......@@ -115,12 +124,14 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
// OnSeekBarChangeListener methods :
@Override
public void onProgressChanged(SeekBar seek, int value, boolean fromTouch) {
/*String t = String.valueOf(value);
mValueText.setText(mSuffix == null ? t : t.concat(" " + mSuffix));*/
if (fromTouch) {
previewVolume(value);
}
}
@Override
public void onStartTrackingTouch(SeekBar seek) {
previewVolume(seek.getProgress());
}
@Override
......@@ -150,7 +161,6 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
// Set the positive button listener and onClick action :
@Override
public void showDialog(Bundle state) {
super.showDialog(state);
Button positiveButton = ((AlertDialog) getDialog()).getButton(AlertDialog.BUTTON_POSITIVE);
......@@ -159,9 +169,7 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
@Override
public void onClick(View v) {
if (shouldPersist()) {
mValue = mSeekBar.getProgress();
persistInt(mSeekBar.getProgress());
callChangeListener(Integer.valueOf(mSeekBar.getProgress()));
......@@ -170,4 +178,63 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee
getDialog().dismiss();
}
// ------------------------------------------------------------------------------------------
private void previewVolume(int value) {
if (mediaPlayer != null) {
try {
mediaPlayer.stop();
} catch (Exception e) {
e.printStackTrace();
}
try {
mediaPlayer.release();
} catch (Exception e) {
e.printStackTrace();
}
}
AssetFileDescriptor afd = mContext
.getResources()
.openRawResourceFd(MeditationSounds.getMeditationSound("gong"));
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(
afd.getFileDescriptor(),
afd.getStartOffset(),
afd.getDeclaredLength());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ALARM)
.build();
mediaPlayer.setAudioAttributes(audioAttributes);
} else {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
}
float mediaVolume = (float) (value * 0.01);
mediaPlayer.setVolume(mediaVolume, mediaVolume);
mediaPlayer
.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(
MediaPlayer mp) {
mp.start();
}
});
mediaPlayer
.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(
MediaPlayer mp) {
mp.release();
}
});
mediaPlayer.prepareAsync();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment