Skip to content

Commit

Permalink
add +/- buttons for frequency in single test
Browse files Browse the repository at this point in the history
add prev / next buttons for test result
  • Loading branch information
woheller69 committed May 4, 2022
1 parent a3c884f commit cc6b8c0
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 73 deletions.
58 changes: 27 additions & 31 deletions app/src/main/java/org/woheller69/audiometry/PerformSingleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public class PerformSingleTest extends AppCompatActivity {
TextView earView;
TextView dBView;
TextView frequencyView;
Button minusView;
Button plusView;
Button volMinusView;
Button volPlusView;
Button freqPlusView;
Button freqMinusView;
private int s=0;
private int i=0;

Expand Down Expand Up @@ -87,37 +89,29 @@ public void run() {
calibrationArray=fileOperations.readCalibration(context);
actualVolume = (minVolume + maxVolume) / 2f;

plusView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
actualVolume = (actualVolume*Math.sqrt(2d));
if (actualVolume>maxVolume) actualVolume=maxVolume;
}
volPlusView.setOnClickListener(v -> {
actualVolume = (actualVolume*Math.sqrt(2d));
if (actualVolume>maxVolume) actualVolume=maxVolume;
});
minusView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
actualVolume = (actualVolume/Math.sqrt(2d));
if (actualVolume <= 1) {
showToast(getString(R.string.error_volume));
actualVolume = 1;
}
volMinusView.setOnClickListener(v -> {
actualVolume = (actualVolume/Math.sqrt(2d));
if (actualVolume <= 1) {
showToast(getString(R.string.error_volume));
actualVolume = 1;
}
});
earView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
s =(s + 1)%2;
}
earView.setOnClickListener(v -> s =(s + 1)%2);
freqPlusView.setOnClickListener(v -> {
int j=i;
i=(i+1)%testFrequencies.length;
actualVolume=actualVolume*Math.pow(10,(calibrationArray[i]-calibrationArray[j])/20);
if (actualVolume>maxVolume) actualVolume=maxVolume;
});
frequencyView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int j=i;
i=(i+1)%testFrequencies.length;
actualVolume=actualVolume*Math.pow(10,(calibrationArray[i]-calibrationArray[j])/20);
if (actualVolume>maxVolume) actualVolume=maxVolume;
}
freqMinusView.setOnClickListener(v -> {
int j=i;
i=(i+testFrequencies.length-1)%testFrequencies.length;
actualVolume=actualVolume*Math.pow(10,(calibrationArray[i]-calibrationArray[j])/20);
if (actualVolume>maxVolume) actualVolume=maxVolume;
});
while (!stopped) {
int frequency = testFrequencies[i];
Expand Down Expand Up @@ -155,8 +149,10 @@ protected void onCreate(Bundle savedInstanceState) {
earView = findViewById(R.id.ear);
frequencyView = findViewById(R.id.frequency);
dBView = findViewById(R.id.db);
minusView = findViewById(R.id.minus);
plusView = findViewById(R.id.plus);
volMinusView = findViewById(R.id.vol_minus);
volPlusView = findViewById(R.id.vol_plus);
freqMinusView = findViewById(R.id.freq_minus);
freqPlusView = findViewById(R.id.freq_plus);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark,getTheme()));
}
Expand Down
31 changes: 26 additions & 5 deletions app/src/main/java/org/woheller69/audiometry/TestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import static org.woheller69.audiometry.PerformTest.testFrequencies;

public class TestData extends AppCompatActivity {

int index;
String[] allSavedTests;
double[][] testResults = new double[2][testFrequencies.length];
double[] calibrationArray = new double[testFrequencies.length];
String fileName;
Expand All @@ -53,15 +54,37 @@ public float unScaleCbr(double cbr) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context=this;
allSavedTests=TestLookup.getAllSavedTests(this);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark,getTheme()));

setContentView(R.layout.activity_test_data);
Intent intent = getIntent();
fileName = intent.getStringExtra(TestLookup.DESIRED_FILE);
index = intent.getIntExtra("Index",0);
fileName = allSavedTests[index];

ImageButton next = (ImageButton) findViewById(R.id.next);
next.setOnClickListener(view -> {
index = (index - 1);
if (index < 0) index = 0;
fileName = allSavedTests[index];
draw();
});

String[] names = fileName.split("-");
ImageButton prev = (ImageButton) findViewById(R.id.prev);
prev.setOnClickListener(view -> {
index = (index + 1);
if (index > allSavedTests.length-1) index = allSavedTests.length-1;
fileName = allSavedTests[index];
draw();
});

draw();

}

private void draw() {
String[] names = fileName.split("-");
String time = DateFormat.getTimeInstance(DateFormat.SHORT).format(Long.parseLong(names[1])) + ", " + DateFormat.getDateInstance(DateFormat.SHORT).format(Long.parseLong(names[1]));
String name = getString(R.string.test_at,time);

Expand Down Expand Up @@ -181,11 +204,9 @@ public int getDecimalDigits() {

chart.setData(data);
chart.invalidate(); // refresh

}



@Override
public boolean onCreateOptionsMenu(Menu menu) {

Expand Down
36 changes: 20 additions & 16 deletions app/src/main/java/org/woheller69/audiometry/TestLookup.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.woheller69.audiometry;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
Expand Down Expand Up @@ -29,11 +30,10 @@

public class TestLookup extends AppCompatActivity {

public final static String DESIRED_FILE = "ut.ewh.audiometrytest.DESIRED_FILE";
String[] allSavedTests;
public void gotoTestData(View view, String fileName){
public void gotoTestData(View view, int index){
Intent intent = new Intent(this, TestData.class);
intent.putExtra(DESIRED_FILE, fileName);
intent.putExtra("Index", index);
startActivity(intent);
}

Expand Down Expand Up @@ -67,18 +67,7 @@ private void createView() {
textview.setGravity(Gravity.CENTER);
layout.addView(textview, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

SharedPreferences prefManager = PreferenceManager.getDefaultSharedPreferences(this);
int user = prefManager.getInt("user",1);

List<String> list = new ArrayList<String>(Arrays.asList(fileList()));
Collections.sort(list,Collections.reverseOrder());
for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) {
String string = iterator.next();
if (string.equals("CalibrationPreferences")) iterator.remove();
else if (user == 1 && string.contains("U2")) iterator.remove();
else if (user == 2 && !string.contains("U2")) iterator.remove();
}
allSavedTests = list.toArray(new String[0]);
allSavedTests = getAllSavedTests(this);

if (allSavedTests.length < 1) {
TextView message = new TextView(this);
Expand Down Expand Up @@ -113,7 +102,7 @@ private void createView() {
int finalI = i;
b.setId(finalI);
registerForContextMenu(b);
b.setOnClickListener(view -> gotoTestData(view, allSavedTests[finalI]));
b.setOnClickListener(view -> gotoTestData(view, finalI));
container.addView(b, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
}
scrollview.addView(container);
Expand All @@ -122,6 +111,21 @@ private void createView() {
}
}

public static String[] getAllSavedTests(Context context) {
SharedPreferences prefManager = PreferenceManager.getDefaultSharedPreferences(context);
int user = prefManager.getInt("user",1);

List<String> list = new ArrayList<String>(Arrays.asList(context.fileList()));
Collections.sort(list,Collections.reverseOrder());
for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) {
String string = iterator.next();
if (string.equals("CalibrationPreferences")) iterator.remove();
else if (user == 1 && string.contains("U2")) iterator.remove();
else if (user == 2 && !string.contains("U2")) iterator.remove();
}
return list.toArray(new String[0]);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo){
super.onCreateContextMenu(menu, v, menuInfo);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_skip_next_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M6,18l8.5,-6L6,6v12zM16,6v12h2V6h-2z"
android:fillColor="#000000"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_skip_previous_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M6,6h2v12L6,18zM9.5,12l8.5,6L18,6z"
android:fillColor="#000000"/>
</vector>
54 changes: 39 additions & 15 deletions app/src/main/res/layout/activity_performsingletest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,32 @@

<TextView
android:id="@+id/frequency"
android:background="@drawable/button_background"
android:text="8000 Hz"
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:background="@drawable/button_background"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="8000 Hz"
android:textColor="@color/white"
android:textStyle="bold"
android:gravity="center_horizontal"/>
android:textSize="40sp"
android:textStyle="bold" />

<TextView
android:id="@+id/db"
android:background="@drawable/button_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/frequency"
android:layout_marginTop="20dp"
android:background="@drawable/button_background"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="20db"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:textColor="@color/white"
android:textStyle="bold"
android:gravity="center_horizontal"/>
android:textSize="40sp"
android:textStyle="bold" />

<Button
android:id="@+id/plus"
android:id="@+id/vol_plus"
android:layout_width="60dp"
android:padding="10dp"
android:background="@drawable/button_background"
Expand All @@ -77,7 +77,7 @@
android:textColor="@color/white"
android:textStyle="bold"/>
<Button
android:id="@+id/minus"
android:id="@+id/vol_minus"
android:layout_width="60dp"
android:padding="10dp"
android:background="@drawable/button_background"
Expand All @@ -90,4 +90,28 @@
android:layout_alignParentStart="true"
android:textStyle="bold"/>

<Button
android:id="@+id/freq_plus"
android:layout_width="60dp"
android:padding="10dp"
android:background="@drawable/button_background"
android:layout_height="wrap_content"
android:layout_below="@id/ear"
android:text="+"
android:textSize="40sp"
android:layout_alignParentEnd="true"
android:textColor="@color/white"
android:textStyle="bold"/>
<Button
android:id="@+id/freq_minus"
android:layout_width="60dp"
android:padding="10dp"
android:background="@drawable/button_background"
android:layout_height="wrap_content"
android:layout_below="@id/ear"
android:text="-"
android:textSize="40sp"
android:textColor="@color/white"
android:layout_alignParentStart="true"
android:textStyle="bold"/>
</RelativeLayout>
Loading

0 comments on commit cc6b8c0

Please sign in to comment.