// Path: android/WALT/app/src/main/java/org/chromium/latency/walt/Utils.java
// static int getIntPreference(Context context, @StringRes int keyId, int defaultValue) {
//     SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
//     return preferences.getInt(context.getString(keyId), defaultValue);
// }


import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.media.AudioManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import static org.chromium.latency.walt.Utils.getIntPreference;
    public void onDestroy() {
        super.onDestroy();
        audioTest.teardown();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button_start_audio:
                chartLayout.setVisibility(View.GONE);
                disableButtons();
                AudioTestType testType = getSelectedTestType();
                switch (testType) {
                    case CONTINUOUS_PLAYBACK:
                    case CONTINUOUS_RECORDING:
                    case DISPLAY_WAVEFORM:
                        audioTest.setAudioMode(AudioTest.AudioMode.CONTINUOUS);
                        audioTest.setPeriod(AudioTest.CONTINUOUS_TEST_PERIOD);
                        break;
                    case COLD_PLAYBACK:
                    case COLD_RECORDING:
                        audioTest.setAudioMode(AudioTest.AudioMode.CONTINUOUS);
                        audioTest.setPeriod(AudioTest.COLD_TEST_PERIOD);
                        break;
                }
                if (testType == AudioTestType.DISPLAY_WAVEFORM) {
                    // Only need to record 1 beep to display wave
                    audioTest.setRecordingRepetitions(1);
                } else {
                    audioTest.setRecordingRepetitions(
// Path: android/WALT/app/src/main/java/org/chromium/latency/walt/Utils.java
// static int getIntPreference(Context context, @StringRes int keyId, int defaultValue) {
//     SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
//     return preferences.getInt(context.getString(keyId), defaultValue);
// }


// Path: android/WALT/app/src/main/java/org/chromium/latency/walt/AudioFragment.java
import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.media.AudioManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.LimitLine;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import static org.chromium.latency.walt.Utils.getIntPreference;

    public void onDestroy() {
        super.onDestroy();
        audioTest.teardown();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button_start_audio:
                chartLayout.setVisibility(View.GONE);
                disableButtons();
                AudioTestType testType = getSelectedTestType();
                switch (testType) {
                    case CONTINUOUS_PLAYBACK:
                    case CONTINUOUS_RECORDING:
                    case DISPLAY_WAVEFORM:
                        audioTest.setAudioMode(AudioTest.AudioMode.CONTINUOUS);
                        audioTest.setPeriod(AudioTest.CONTINUOUS_TEST_PERIOD);
                        break;
                    case COLD_PLAYBACK:
                    case COLD_RECORDING:
                        audioTest.setAudioMode(AudioTest.AudioMode.CONTINUOUS);
                        audioTest.setPeriod(AudioTest.COLD_TEST_PERIOD);
                        break;
                }
                if (testType == AudioTestType.DISPLAY_WAVEFORM) {
                    // Only need to record 1 beep to display wave
                    audioTest.setRecordingRepetitions(1);
                } else {
                    audioTest.setRecordingRepetitions(
                            getIntPreference(getContext(), R.string.preference_audio_in_reps, 5));