3 Commits be4c8018ee ... 45e0ebe36d

Author SHA1 Message Date
  waelk10 45e0ebe36d Update dependencies 1 year ago
  waelk10 05e74be480 Merge remote-tracking branch 'origin/master' 1 year ago
  waelk10 cdb269aef8 Various bugfixes, code cleanup and updates. 1 year ago

+ 10 - 0
.idea/jarRepositories.xml

@@ -21,5 +21,15 @@
       <option name="name" value="Google" />
       <option name="url" value="https://dl.google.com/dl/android/maven2/" />
     </remote-repository>
+    <remote-repository>
+      <option name="id" value="MavenRepo" />
+      <option name="name" value="MavenRepo" />
+      <option name="url" value="https://repo.maven.apache.org/maven2/" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="maven" />
+      <option name="name" value="maven" />
+      <option name="url" value="https://jitpack.io" />
+    </remote-repository>
   </component>
 </project>

+ 1 - 1
.idea/misc.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="JDK" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">

+ 1 - 1
app/build.gradle

@@ -45,6 +45,6 @@ dependencies {
     testImplementation 'junit:junit:4.13.2'
     androidTestImplementation 'androidx.test:runner:1.4.0'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
-	implementation 'com.binaryfork:spanny:1.0.4'
+	implementation 'com.github.GustavoRoss:Spanny:1.0.3'
     implementation 'com.fabiendevos:nanotasks:1.1.0'
 }

+ 5 - 5
app/src/main/java/tech/waelk/radioactive/metronome/AudioGenerator.java

@@ -28,7 +28,7 @@ import android.os.Build;
 public class AudioGenerator {
 	private final static double positiveRound = 1.0;
 	private final static double negativeRound = -1.0;
-	private int sampleRate;
+	private final int sampleRate;
 	private AudioTrack audioTrack;
 
 	public AudioGenerator(int sampleRate) {
@@ -90,7 +90,7 @@ public class AudioGenerator {
 			sample[i] = 0;
 		}*/
 
-		//resynthesize the wave
+		//re-synthesize the wave
 		for (int i = 0; i < sample.length - 1;) {
 			j = 0;
 			while(j < length_high && i < sample.length){
@@ -138,11 +138,11 @@ public class AudioGenerator {
 				AudioFormat.ENCODING_PCM_16BIT, sampleRate,
 				AudioTrack.MODE_STREAM);
 		else {
-			AudioAttributes.Builder audioAttribuitesBuilder = new AudioAttributes.Builder();
-			audioAttribuitesBuilder.setUsage(AudioAttributes.USAGE_MEDIA).setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
+			AudioAttributes.Builder audioAttributesBuilder = new AudioAttributes.Builder();
+			audioAttributesBuilder.setUsage(AudioAttributes.USAGE_MEDIA).setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
 			AudioFormat.Builder audioFormatBuilder = new AudioFormat.Builder();
 			audioFormatBuilder.setEncoding(AudioFormat.ENCODING_PCM_16BIT).setSampleRate(sampleRate).setChannelMask(AudioFormat.CHANNEL_OUT_MONO);
-			audioTrack = new AudioTrack.Builder().setAudioAttributes(audioAttribuitesBuilder.build()).setPerformanceMode(AudioTrack.PERFORMANCE_MODE_LOW_LATENCY).setAudioFormat(audioFormatBuilder.build()).build();
+			audioTrack = new AudioTrack.Builder().setAudioAttributes(audioAttributesBuilder.build()).setPerformanceMode(AudioTrack.PERFORMANCE_MODE_LOW_LATENCY).setAudioFormat(audioFormatBuilder.build()).build();
 		}
 		audioTrack.play();
 	}

+ 1 - 1
app/src/main/java/tech/waelk/radioactive/metronome/Metronome.java

@@ -34,7 +34,7 @@ public class Metronome {
 	private double thinness;
 	private String wave;
 	private boolean play = true;
-	private AudioGenerator audioGenerator;
+	private final AudioGenerator audioGenerator;
 
 	public Metronome(String waveType) {
 		audioGenerator = new AudioGenerator(sampleRate);

+ 167 - 251
app/src/main/java/tech/waelk/radioactive/metronome/MetronomeActivity.java

@@ -1,28 +1,27 @@
 /*
- * Copyright (c) 2020.
- *  This file is part of Metronome.
+ * Copyright (c) 2019.
+ * This file is part of Metronome.
  *
- * Metronome is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ *      Metronome is free software: you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation, either version 3 of the License, or
+ *      (at your option) any later version.
  *
- * Metronome is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metronome.  If not, see <http://www.gnu.org/licenses/>.
+ *      Metronome is distributed in the hope that it will be useful,
+ *      but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *      GNU General Public License for more details.
  *
+ *      You should have received a copy of the GNU General Public License
+ *      along with Metronome.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 package tech.waelk.radioactive.metronome;
 
+import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.Context;
-import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.pm.PackageInfo;
@@ -37,7 +36,6 @@ import android.view.MenuItem;
 import android.view.View;
 import android.view.WindowManager;
 import android.widget.Button;
-import android.widget.CompoundButton;
 import android.widget.RadioButton;
 import android.widget.RadioGroup;
 import android.widget.TextView;
@@ -45,7 +43,6 @@ import android.widget.Toast;
 import android.widget.ToggleButton;
 
 import com.binaryfork.spanny.Spanny;
-import com.nanotasks.BackgroundWork;
 import com.nanotasks.Completion;
 import com.nanotasks.Tasks;
 
@@ -63,10 +60,7 @@ import static tech.waelk.radioactive.metronome.SaveDialogActivity.DATA_STORAGE_F
  * http://masterex.github.io/archive/2012/05/28/android-audio-synthesis.html - Metronome base code
  */
 
-//TODO: EXTREMELY IMPORTANT: WHENEVER YOU PUSH A NEW VERSION TO GITHUB, MAKE SURE TO MANUALLY UPDATE THE CHANGES OF "build.gradle" TO "build.gradle-sample", WHILE EXCLUDING THE SIGNING CONFIG!!!!!!
-
 public class MetronomeActivity extends Activity {
-	// Constants.
 	public final static boolean AUTO_SAVE_FLAG_FALSE = false;
 	public final static int REQUEST_ID = 1;
 	public final static String PREFS_NAME = "DbPrefsFile";
@@ -77,7 +71,6 @@ public class MetronomeActivity extends Activity {
 	public final static String DIALOG_SAVE_BEAT_SOUND = "INTENT_BEAT_SOUND_DATA";
 	public final static String DIALOG_SAVE_SOUND = "INTENT_SOUND_DATA";
 	public final static String DIALOG_SAVE_WAVE = "INTENT_WAVE_DATA";
-	private final static String NEWLINE = "\n";
 	private final static int BPM_INDEX = 0;
 	private final static int BEATS_INDEX = 1;
 	private final static int BEAT_SOUND_INDEX = 2;
@@ -89,7 +82,8 @@ public class MetronomeActivity extends Activity {
 	private final static double SOUND = 880;
 	private final static double BEAT_SOUND = 440;
 	private final static double THINNESS = 0.2;
-	private final static double DIALOG_TO_SCREEN_RATIO = 0.95;
+	private final static double ABOUT_DIALOG_WIDTH_PERCENTAGE = 0.8;
+	private final static double ABOUT_DIALOG_HEIGHT_PERCENTAGE = 0.4;
 	private final static boolean AUTO_SAVE_FLAG_TRUE = true;
 	private final static String TAG = "MetronomeActivity";
 
@@ -158,14 +152,9 @@ public class MetronomeActivity extends Activity {
 
 
 	//used for the tone menu button
-	private View.OnClickListener toneClickListener = new View.OnClickListener() {
-		@Override
-		public void onClick(View v) {
-			noteDialog();
-		}
-	};
+	private final View.OnClickListener toneClickListener = v -> noteDialog();
 	//used for setting the number of the bea(s)ts per minute
-	private View.OnClickListener bpmClickListener = new View.OnClickListener() {
+	private final View.OnClickListener bpmClickListener = new View.OnClickListener() {
 		@Override
 		public void onClick(View v) {
 			//stop and reset the metronome on change of values
@@ -201,7 +190,7 @@ public class MetronomeActivity extends Activity {
 		}
 	};
 	//used for the tap tempo tap button
-	private View.OnClickListener tapClickListener = new View.OnClickListener() {
+	private final View.OnClickListener tapClickListener = new View.OnClickListener() {
 		@Override
 		public void onClick(View v) {
 			//stop the metronome
@@ -221,7 +210,7 @@ public class MetronomeActivity extends Activity {
 			}
 		}
 	};
-	private View.OnClickListener stopTapClickListener = new View.OnClickListener() {
+	private final View.OnClickListener stopTapClickListener = new View.OnClickListener() {
 		@Override
 		public void onClick(View v) {
 			//check if there are enough taps
@@ -248,7 +237,7 @@ public class MetronomeActivity extends Activity {
 		}
 	};
 	//used for rounding the BPM value up
-	private View.OnClickListener roundUpListener = new View.OnClickListener() {
+	private final View.OnClickListener roundUpListener = new View.OnClickListener() {
 		@Override
 		public void onClick(View v) {
 			//stop and reset the metronome on change of values
@@ -263,7 +252,7 @@ public class MetronomeActivity extends Activity {
 		}
 	};
 	//used for rounding the BPM value down
-	private View.OnClickListener roundDownListener = new View.OnClickListener() {
+	private final View.OnClickListener roundDownListener = new View.OnClickListener() {
 		@Override
 		public void onClick(View v) {
 			//stop and reset the metronome on change of values
@@ -281,7 +270,7 @@ public class MetronomeActivity extends Activity {
 		}
 	};
 	//long click up button
-	private View.OnLongClickListener roundUpLongClickListener = new View.OnLongClickListener() {
+	private final View.OnLongClickListener roundUpLongClickListener = new View.OnLongClickListener() {
 		@Override
 		public boolean onLongClick(View v) {
 			Toast.makeText(contextActivity, getResources().getText(R.string.round_up_toast), Toast.LENGTH_SHORT).show();
@@ -289,7 +278,7 @@ public class MetronomeActivity extends Activity {
 		}
 	};
 	//long click down button
-	private View.OnLongClickListener roundDownLongClickListener = new View.OnLongClickListener() {
+	private final View.OnLongClickListener roundDownLongClickListener = new View.OnLongClickListener() {
 		@Override
 		public boolean onLongClick(View v) {
 			Toast.makeText(contextActivity, getResources().getText(R.string.round_down_toast), Toast.LENGTH_SHORT).show();
@@ -297,7 +286,7 @@ public class MetronomeActivity extends Activity {
 		}
 	};
 	//used for setting the number of beats
-	private View.OnClickListener beatsClickListener = new View.OnClickListener() {
+	private final View.OnClickListener beatsClickListener = new View.OnClickListener() {
 		@Override
 		public void onClick(View v) {
 			//stop and reset the metronome on change of values
@@ -432,68 +421,47 @@ public class MetronomeActivity extends Activity {
 		currentMetronome = metronome.copyMetronome();
 
 		//Bottom action button listeners
-		deleteButton.setOnClickListener(new View.OnClickListener() {
-			@Override
-			public void onClick(View v) {
-				if (uuid != null && delete(uuid))
-					Toast.makeText(contextActivity, getResources().getText(R.string.deleted), Toast.LENGTH_SHORT).show();
-				else
-					Toast.makeText(contextActivity, getResources().getText(R.string.nothing_delete), Toast.LENGTH_SHORT).show();
-			}
-		});
-		saveButton.setOnClickListener(new View.OnClickListener() {
-			@Override
-			public void onClick(View v) {
-				saveDialog();
-			}
-		});
-		restoreButton.setOnClickListener(new View.OnClickListener() {
-			@Override
-			public void onClick(View v) {
-				restoreDialog();
-			}
+		deleteButton.setOnClickListener(v -> {
+			if (uuid != null && delete(uuid))
+				Toast.makeText(contextActivity, getResources().getText(R.string.deleted), Toast.LENGTH_SHORT).show();
+			else
+				Toast.makeText(contextActivity, getResources().getText(R.string.nothing_delete), Toast.LENGTH_SHORT).show();
 		});
+		saveButton.setOnClickListener(v -> saveDialog());
+		restoreButton.setOnClickListener(v -> restoreDialog());
 
 		//start/stop
-		startButton.setOnClickListener(new View.OnClickListener() {
-			@Override
-			public void onClick(View v) {
-				//sanity check for the values
-				if (bpm > 0 && beats > 0)
-					if (!flag) {
-						//update the values
-						metronome.setBeat(beats);
-						metronome.setBpm(bpm);
-						metronome.setBeatSound(beatSound);
-						metronome.setSound(sound);
-						metronome.setThinness(THINNESS);
-						//reset the current metronome and re-copy
-						metronomeReset();
-						//execute the metronome with current settings asynchronously
-						Tasks.executeInBackground(contextActivity, new BackgroundWork<Boolean>() {
-							@Override
-							public Boolean doInBackground() {
-								return currentMetronome.playRes();
-							}
-						}, new Completion<Boolean>() {
-							@Override
-							public void onSuccess(Context context, Boolean result) {
-								Log.i(TAG, "Gracefully terminated background metronome task.");
-							}
-
-							@Override
-							public void onError(Context context, Exception e) {
-								Log.e(TAG, "Error in background metronome task, exception:");
-								Log.e(TAG, e.toString());
-							}
-						});
-						flag = true;
-					} else {
-						metronomeStop();
-					}
-				else
-					Toast.makeText(contextActivity, getResources().getText(R.string.values_set), Toast.LENGTH_SHORT).show();
-			}
+		startButton.setOnClickListener(v -> {
+			//sanity check for the values
+			if (bpm > 0 && beats > 0)
+				if (!flag) {
+					//update the values
+					metronome.setBeat(beats);
+					metronome.setBpm(bpm);
+					metronome.setBeatSound(beatSound);
+					metronome.setSound(sound);
+					metronome.setThinness(THINNESS);
+					//reset the current metronome and re-copy
+					metronomeReset();
+					//execute the metronome with current settings asynchronously
+					Tasks.executeInBackground(contextActivity, () -> currentMetronome.playRes(), new Completion<Boolean>() {
+						@Override
+						public void onSuccess(Context context, Boolean result) {
+							Log.i(TAG, "Gracefully terminated background metronome task.");
+						}
+
+						@Override
+						public void onError(Context context, Exception e) {
+							Log.e(TAG, "Error in background metronome task, exception:");
+							Log.e(TAG, e.toString());
+						}
+					});
+					flag = true;
+				} else {
+					metronomeStop();
+				}
+			else
+				Toast.makeText(contextActivity, getResources().getText(R.string.values_set), Toast.LENGTH_SHORT).show();
 		});
 
 		//number of the bea(s)ts per minute buttons
@@ -522,14 +490,11 @@ public class MetronomeActivity extends Activity {
 		toneButton.setOnClickListener(toneClickListener);
 
 		//toggle button, keep screen on
-		toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
-			@Override
-			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-				if (isChecked)
-					getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
-				else
-					getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
-			}
+		toggleButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
+			if (isChecked)
+				getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+			else
+				getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
 		});
 	}
 
@@ -565,7 +530,7 @@ public class MetronomeActivity extends Activity {
 				fileOutputStream.write("".getBytes());
 				fileOutputStream.close();
 			} catch (IOException e) {
-				Log.w(TAG, "failed to read/write!\n" + e.toString());
+				Log.w(TAG, "failed to read/write!\n" + e);
 			}
 		}
 		data = MiscUtils.prepareForStorage(getResources().getText(R.string.autosave_name).toString(), beats, bpm, MetronomeActivity.AUTO_SAVE_FLAG_TRUE, beatSound, sound, UUID.randomUUID().toString(), wave);
@@ -578,7 +543,7 @@ public class MetronomeActivity extends Activity {
 			fileOutputStream.write(data.getBytes());
 			fileOutputStream.close();
 		} catch (IOException ex) {
-			Log.w(TAG, "failed to save!\n" + ex.toString());
+			Log.w(TAG, "failed to save!\n" + ex);
 			Toast.makeText(MetronomeActivity.this, getResources().getText(R.string.save_fail_toast), Toast.LENGTH_SHORT).show();
 			success = false;
 		}
@@ -602,11 +567,12 @@ public class MetronomeActivity extends Activity {
 	//overflow menu logic
 	@Override
 	public boolean onOptionsItemSelected(MenuItem item) {
-		if (item.getItemId() == R.id.action_about) {
+		if (item.getItemId() == R.id.action_about){
 			metronomeStop();
 			aboutDialog();
 			return true;
 		}
+
 		return super.onOptionsItemSelected(item);
 	}
 
@@ -668,7 +634,7 @@ public class MetronomeActivity extends Activity {
 				fileOutputStream.close();
 				return true;
 			} catch (IOException e) {
-				Log.w(TAG, "failed to delete!\n" + e.toString());
+				Log.w(TAG, "failed to delete!\n" + e);
 				return false;
 			}
 		}
@@ -684,50 +650,36 @@ public class MetronomeActivity extends Activity {
 		final String[] notes = pitchGenerator.getNotes();
 		AlertDialog.Builder builder = new AlertDialog.Builder(contextActivity, R.style.DialogSaveTheme);
 		//change size
-		int width = (int)(contextActivity.getResources().getDisplayMetrics().widthPixels*DIALOG_TO_SCREEN_RATIO);
-		int height = (int)(contextActivity.getResources().getDisplayMetrics().heightPixels*DIALOG_TO_SCREEN_RATIO);
-		builder.setSingleChoiceItems(notes, 0, null).setPositiveButton(R.string.tock, new DialogInterface.OnClickListener() {
-			@Override
-			public void onClick(DialogInterface dialog, int which) {
-				//dismiss the dialog
-				dialog.dismiss();
-				//get selected entry/position/row
-				if (((AlertDialog) dialog).getListView() != null) {
-					int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
-					double[] freqs = pitchGenerator.getFreqs();
-					beatSound = freqs[selectedPosition];
-				}
-			}
-		}).setNegativeButton(R.string.tick, new DialogInterface.OnClickListener() {
-			@Override
-			public void onClick(DialogInterface dialog, int which) {
-				//dismiss the dialog
-				dialog.dismiss();
-				//get selected entry/position/row
-				if (((AlertDialog) dialog).getListView() != null) {
-					int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
-					double[] freqs = pitchGenerator.getFreqs();
-					sound = freqs[selectedPosition];
-				}
+		int width = (int)(contextActivity.getResources().getDisplayMetrics().widthPixels*0.9);
+		int height = (int)(contextActivity.getResources().getDisplayMetrics().heightPixels*0.9);
+		builder.setSingleChoiceItems(notes, 0, null).setPositiveButton(R.string.tock, (dialog, which) -> {
+			//dismiss the dialog
+			dialog.dismiss();
+			//get selected entry/position/row
+			if (((AlertDialog) dialog).getListView() != null) {
+				int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
+				double[] freqs = pitchGenerator.getFreqs();
+				beatSound = freqs[selectedPosition];
 			}
-		}).setNeutralButton(R.string.reset, new DialogInterface.OnClickListener() {
-			@Override
-			public void onClick(DialogInterface dialog, int which) {
-				//dismiss the dialog
-				dialog.dismiss();
-				//restore default values
-				sound = SOUND;
-				beatSound = BEAT_SOUND;
+		}).setNegativeButton(R.string.tick, (dialog, which) -> {
+			//dismiss the dialog
+			dialog.dismiss();
+			//get selected entry/position/row
+			if (((AlertDialog) dialog).getListView() != null) {
+				int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
+				double[] freqs = pitchGenerator.getFreqs();
+				sound = freqs[selectedPosition];
 			}
+		}).setNeutralButton(R.string.reset, (dialog, which) -> {
+			//dismiss the dialog
+			dialog.dismiss();
+			//restore default values
+			sound = SOUND;
+			beatSound = BEAT_SOUND;
 		});
 		AlertDialog dialog = builder.create();
 		dialog.show();
-		try{
 		dialog.getWindow().setLayout(width, height);
-		}catch (NullPointerException npe){
-			Log.e(TAG, "Error in creating alert-dialog for the pitches.");
-			Log.e(TAG, npe.toString());
-		}
 	}
 
 	//restore dialog
@@ -740,95 +692,72 @@ public class MetronomeActivity extends Activity {
 		if (data != null && !data.isEmpty()) {
 			final String[][] parsedData = MiscUtils.parseSaveDataList(data);
 			final String[][] fullParsedData = MiscUtils.parseSaveDataArrays(data);
-			if (parsedData != null) {
-				//change size
-				int width = (int)(contextActivity.getResources().getDisplayMetrics().widthPixels*0.9);
-				int height = (int)(contextActivity.getResources().getDisplayMetrics().heightPixels*0.9);
-				AlertDialog.Builder builder = new AlertDialog.Builder(contextActivity, R.style.DialogSaveTheme);
-				final String[] titles = getTitles(parsedData);
-				builder.setSingleChoiceItems(titles, 0, null).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
-					public void onClick(DialogInterface dialog, int whichButton) {
-						//dismiss the dialog
-						dialog.dismiss();
-						//get selected entry/position/row
-						if (((AlertDialog) dialog).getListView() != null) {
-							int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
-							//set the values, for the variables and the UI
-							beats = Integer.parseInt(fullParsedData[selectedPosition][MiscUtils.BEATS_INDEX]);
-							bpm = Integer.parseInt(fullParsedData[selectedPosition][MiscUtils.BPM_INDEX]);
-							uuid = fullParsedData[selectedPosition][MiscUtils.UUID_INDEX];
-							beatSound = Double.parseDouble(fullParsedData[selectedPosition][MiscUtils.BEAT_SOUND_INDEX]);
-							sound = Double.parseDouble(fullParsedData[selectedPosition][MiscUtils.SOUND_INDEX]);
-							wave = fullParsedData[selectedPosition][MiscUtils.WAVE_INDEX];
-							textViewBPM.setText(String.format(Locale.US, "%d", bpm));
-							textViewBeats.setText(String.format(Locale.US, "%d", beats));
-							AudioGenerator audioGenerator = metronome.getAudioGenerator();
-							metronome = null;
-							//initialize wavetype if null
-							if (wave == null)
-								wave = Metronome.WAVE_TYPE_SINE;
-							metronome = new Metronome(audioGenerator, wave, THINNESS);
-							metronome.setBeatSound(beatSound);
-							metronome.setSound(sound);
-							metronome.setBpm(bpm);
-							metronome.setBeat(beats);
-							currentMetronome = metronome.copyMetronome();
-
-							//reset the wave UI
-							radioGroup.clearCheck();
-							//set the right button
-							switch (wave) {
-								case Metronome.WAVE_TYPE_SINE:
-									radioButtonSine.setChecked(true);
-									break;
-								case Metronome.WAVE_TYPE_PWM_THIN:
-									radioButtonPWM.setChecked(true);
-									break;
-								case Metronome.WAVE_TYPE_PWM:
-									radioButtonSquare.setChecked(true);
-									break;
-								case Metronome.WAVE_TYPE_SAWTOOTH:
-									radioButtonSawtooth.setChecked(true);
-									break;
-							}
-						}
-					}
-				}).setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
-					@Override
-					public void onClick(DialogInterface dialogInterface, int i) {
-						//dismiss the dialog
-						dialogInterface.dismiss();
-					}
-				}).setNegativeButton(R.string.delete, new DialogInterface.OnClickListener() {
-					@Override
-					public void onClick(DialogInterface dialog, int which) {
-						//dismiss the dialog
-						dialog.dismiss();
-						//get selected entry/position/row
-						if (((AlertDialog) dialog).getListView() != null) {
-							int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
-							//delete the selection
-							delete(parsedData[selectedPosition][1]);
-						}
+			//change size
+			int width = (int)(contextActivity.getResources().getDisplayMetrics().widthPixels*0.9);
+			int height = (int)(contextActivity.getResources().getDisplayMetrics().heightPixels*0.9);
+			AlertDialog.Builder builder = new AlertDialog.Builder(contextActivity, R.style.DialogSaveTheme);
+			final String[] titles = getTitles(parsedData);
+			builder.setSingleChoiceItems(titles, 0, null).setPositiveButton(R.string.ok, (dialog, whichButton) -> {
+				//dismiss the dialog
+				dialog.dismiss();
+				//get selected entry/position/row
+				if (((AlertDialog) dialog).getListView() != null) {
+					int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
+					//set the values, for the variables and the UI
+					beats = Integer.parseInt(fullParsedData[selectedPosition][MiscUtils.BEATS_INDEX]);
+					bpm = Integer.parseInt(fullParsedData[selectedPosition][MiscUtils.BPM_INDEX]);
+					uuid = fullParsedData[selectedPosition][MiscUtils.UUID_INDEX];
+					beatSound = Double.parseDouble(fullParsedData[selectedPosition][MiscUtils.BEAT_SOUND_INDEX]);
+					sound = Double.parseDouble(fullParsedData[selectedPosition][MiscUtils.SOUND_INDEX]);
+					wave = fullParsedData[selectedPosition][MiscUtils.WAVE_INDEX];
+					textViewBPM.setText(String.format(Locale.US, "%d", bpm));
+					textViewBeats.setText(String.format(Locale.US, "%d", beats));
+					AudioGenerator audioGenerator = metronome.getAudioGenerator();
+					metronome = null;
+					//initialize wavetype if null
+					if (wave == null)
+						wave = Metronome.WAVE_TYPE_SINE;
+					metronome = new Metronome(audioGenerator, wave, THINNESS);
+					metronome.setBeatSound(beatSound);
+					metronome.setSound(sound);
+					metronome.setBpm(bpm);
+					metronome.setBeat(beats);
+					currentMetronome = metronome.copyMetronome();
+
+					//reset the wave UI
+					radioGroup.clearCheck();
+					//set the right button
+					switch (wave) {
+						case Metronome.WAVE_TYPE_SINE:
+							radioButtonSine.setChecked(true);
+							break;
+						case Metronome.WAVE_TYPE_PWM_THIN:
+							radioButtonPWM.setChecked(true);
+							break;
+						case Metronome.WAVE_TYPE_PWM:
+							radioButtonSquare.setChecked(true);
+							break;
+						case Metronome.WAVE_TYPE_SAWTOOTH:
+							radioButtonSawtooth.setChecked(true);
+							break;
 					}
-				});
-				AlertDialog dialog = builder.create();
-				dialog.show();
-				//dialog.getWindow().setLayout(width, height);
-			} else {
-				Toast.makeText(contextActivity, getResources().getText(R.string.no_saved_presets_toast), Toast.LENGTH_SHORT).show();
-				SaveValues saveValues = getAutoSaveValues(data);
-				if (saveValues != null) {
-					double[] valuesArray = saveValues.getValues();
-					beats = (int) valuesArray[BEATS_INDEX];
-					bpm = (int) valuesArray[BPM_INDEX];
-					beatSound = valuesArray[BEAT_SOUND_INDEX];
-					sound = valuesArray[SOUND_INDEX];
-					uuid = valuesArray[UUID_INDEX] + "";
-					//String[] strings = MiscUtils.parseSaveData(data);
-					wave = saveValues.getWave();
 				}
-			}
+			}).setNeutralButton(R.string.cancel, (dialogInterface, i) -> {
+				//dismiss the dialog
+				dialogInterface.dismiss();
+			}).setNegativeButton(R.string.delete, (dialog, which) -> {
+				//dismiss the dialog
+				dialog.dismiss();
+				//get selected entry/position/row
+				if (((AlertDialog) dialog).getListView() != null) {
+					int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
+					//delete the selection
+					delete(parsedData[selectedPosition][1]);
+				}
+			});
+			AlertDialog dialog = builder.create();
+			dialog.show();
+			//dialog.getWindow().setLayout(width, height);
 		}else {
 			Log.i(TAG, "user attempted restore without having any data to restore from!");
 			Toast.makeText(MetronomeActivity.this,"Nothing saved to restore from!", Toast.LENGTH_LONG).show();
@@ -851,6 +780,7 @@ public class MetronomeActivity extends Activity {
 	}
 
 	//about dialog
+	@SuppressLint("UseCompatLoadingForDrawables")
 	private void aboutDialog() {
 		//for version info extraction
 		String version = "\n\nVersion Name: ";
@@ -872,15 +802,7 @@ public class MetronomeActivity extends Activity {
 		builder.setView(dialogView);
 		TextView textView = dialogView.findViewById(R.id.textViewAbout);
 		//build the text
-		StringBuilder stringBuilder = new StringBuilder();
-		stringBuilder.append(getString(R.string.app_name)).append(NEWLINE);
-		stringBuilder.append(getString(R.string.email)).append(NEWLINE);
-		stringBuilder.append(getString(R.string.copyright)).append(NEWLINE);
-		stringBuilder.append(version).append(NEWLINE).append(NEWLINE);
-		stringBuilder.append(getString(R.string.about_note)).append(NEWLINE).append(NEWLINE);
-		stringBuilder.append(getString(R.string.license)).append(NEWLINE).append(NEWLINE);
-		stringBuilder.append(getString(R.string.radioactive));
-		Spanny message = new Spanny(stringBuilder.toString());
+		Spanny message = new Spanny(getString(R.string.app_name) + '\n', new UnderlineSpan()).append('\n' + getString(R.string.email)).append('\n' + getString(R.string.copyright)).append('\n' + version + '\n').append('\n' + getString(R.string.about_note)).append("\n\n" + getString(R.string.license)).append("\n\n" + this.getResources().getText(R.string.website) + this.getResources().getText(R.string.radioactive));
 		builder.setTitle(getString(R.string.about));
 		//add the icon
 		builder.setIcon(getResources().getDrawable(R.drawable.ic_launcher, getTheme()));
@@ -892,14 +814,9 @@ public class MetronomeActivity extends Activity {
 		dialog.show();
 
 		//change size
-		int width = (int)(contextActivity.getResources().getDisplayMetrics().widthPixels*DIALOG_TO_SCREEN_RATIO);
-		int height = (int)(contextActivity.getResources().getDisplayMetrics().heightPixels*DIALOG_TO_SCREEN_RATIO);
-		try {
-			dialog.getWindow().setLayout(width, height);
-		}catch (NullPointerException npe){
-			Log.e(TAG, "Error in creating alert-dialog for the \"about\" menu.");
-			Log.e(TAG, npe.toString());
-		}
+		int width = (int)(contextActivity.getResources().getDisplayMetrics().widthPixels * ABOUT_DIALOG_WIDTH_PERCENTAGE);
+		int height = (int)(contextActivity.getResources().getDisplayMetrics().heightPixels * ABOUT_DIALOG_HEIGHT_PERCENTAGE);
+	//	dialog.getWindow().setLayout(width, height);
 	}
 
 	//used to find and return the values of the auto-save preset
@@ -923,8 +840,7 @@ public class MetronomeActivity extends Activity {
 	private String getUuid(String data) {
 		if (data == null)
 			return null;
-		String dataString;
-		dataString = MiscUtils.getAutoSave(data, MetronomeActivity.this);
+		String dataString = MiscUtils.getAutoSave(data, MetronomeActivity.this);
 		if (dataString == null)
 			return null;
 		String[] parsedDataStrings = MiscUtils.parseSaveData(dataString);
@@ -952,7 +868,7 @@ public class MetronomeActivity extends Activity {
 
 	//helper function used to reset the metronome and related variables
 	private void metronomeReset() {
-		//stop the metronome and reset it
+		//stop the metronome
 		currentMetronome.setBeatSound(0.0);
 		currentMetronome.setBeat(0);
 		currentMetronome.setSound(0.0);

+ 8 - 7
app/src/main/java/tech/waelk/radioactive/metronome/MiscUtils.java

@@ -63,14 +63,15 @@ public class MiscUtils {
 	//prepare the saved data for a list display
 	public static String[][] parseSaveDataList(String data) {
 		int i = 0, j = 0, count = 1;
-		StringBuffer stringBuffer;
-		List<String> stringList = new ArrayList<String>();
+		StringBuilder stringBuffer;
+		List<String> stringList = new ArrayList<>();
 		String[][] results;
 		while (i < data.length()) {
 			if (count == 9)
 				count = 1;
-			stringBuffer = new StringBuffer();
-			while (data.charAt(i) != separator && data.charAt(i) != newline && i < data.length()) {
+			stringBuffer = new StringBuilder();
+			while (data.charAt(i) != separator && data.charAt(i) != newline) {
+				data.length();
 				stringBuffer.append(data.charAt(i));
 				i++;
 			}
@@ -115,7 +116,7 @@ public class MiscUtils {
 	public static String[][] parseSaveDataArrays(String data) {
 		int i = 0, j, index;
 		String[] tmpData;
-		List<String> stringList = new ArrayList<String>();
+		List<String> stringList = new ArrayList<>();
 		String[][] results;
 		while (i < data.length()) {
 			index = newlineIndex(data, i);
@@ -222,7 +223,7 @@ public class MiscUtils {
 
 	//read the data from the file
 	public static String readSavedData(Context context) {
-		StringBuffer stringBuffer = new StringBuffer();
+		StringBuilder stringBuffer = new StringBuilder();
 		if (!fileExists(context, SaveDialogActivity.DATA_STORAGE_FILE_NAME))
 			return null;
 		try {
@@ -236,7 +237,7 @@ public class MiscUtils {
 			}
 			inputStreamReader.close();
 		} catch (IOException e) {
-			Log.w(READ_LOG_TAG, "failed to read!\n" + e.toString());
+			Log.w(READ_LOG_TAG, "failed to read!\n" + e);
 			return null;
 		}
 		return stringBuffer.toString();

+ 4 - 4
app/src/main/java/tech/waelk/radioactive/metronome/PitchGenerator.java

@@ -41,8 +41,8 @@ public class PitchGenerator {
 	private final static String INDICATOR = "-";
 	private final static String[] BASE_SCALE = {"A", INDICATOR, "A#", "Bb", "B", "C", INDICATOR, "C#", "Db", "D", INDICATOR, "D#", "Eb", "E", "F", INDICATOR, "F#", "Gb", "G", INDICATOR, "G#", "Ab"};
 
-	private double[] freqs;
-	private String[] notes;
+	private final double[] freqs;
+	private final String[] notes;
 
 	public PitchGenerator() {
 		this.freqs = new double[LENGTH];
@@ -75,11 +75,11 @@ public class PitchGenerator {
 				this.notes[i] = BASE_SCALE[j] + (((i - NOTES_LOOP_OFFSET) / NOTES_IN_OCTAVE) + 1) + '/';
 				j++;
 				this.notes[i] = this.notes[i] + BASE_SCALE[j] + (((i - NOTES_LOOP_OFFSET) / NOTES_IN_OCTAVE) + 1);
-				j++;
 			} else {
 				this.notes[i] = BASE_SCALE[j] + (((i - NOTES_LOOP_OFFSET) / NOTES_IN_OCTAVE) + 1);
-				j++;
 			}
+			// Increase in both cases.
+			j++;
 		}
 		return this.notes;
 	}

+ 3 - 3
app/src/main/java/tech/waelk/radioactive/metronome/RepeatListener.java

@@ -37,13 +37,13 @@ import android.view.View.OnTouchListener;
  */
 public class RepeatListener implements OnTouchListener {
 
-	private Handler handler = new Handler();
+	private final Handler handler = new Handler();
 
-	private int initialInterval;
+	private final int initialInterval;
 	private final int normalInterval;
 	private final OnClickListener clickListener;
 
-	private Runnable handlerRunnable = new Runnable() {
+	private final Runnable handlerRunnable = new Runnable() {
 		@Override
 		public void run() {
 			handler.postDelayed(this, normalInterval);

+ 0 - 0
app/src/main/java/tech/waelk/radioactive/metronome/SaveDialogActivity.java


Some files were not shown because too many files changed in this diff