|
@@ -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);
|