Skip to content

Commit

Permalink
added a discrete seek bar for sample rate selection for values : 8000…
Browse files Browse the repository at this point in the history
…, 12000, 16000, 22000, 32000, 44000 Hz
  • Loading branch information
ltrudu committed Aug 2, 2024
1 parent e0831d9 commit 423e1a2
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 21 deletions.
4 changes: 2 additions & 2 deletions hsdemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.zebra.hsdemo"
minSdk 33
targetSdk 34
versionCode 2
versionName "1.1"
versionCode 3
versionName "1.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
33 changes: 30 additions & 3 deletions hsdemo/src/main/java/com/zebra/hsdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -51,13 +53,13 @@ public class MainActivity extends AppCompatActivity {
AudioManager playAudioManager = null;
AudioRecord recorder = null;
Thread recordingThread = null;
MediaPlayer mp = null;
int bufSize = 0;
boolean isRecording = false;
float recordingGain = 1.0f;
float replayGain = 15.0f;
float replayGain = 10.0f;

public static final int sampleRate = 44000;
final static int[] sampleRatevalues = {8000, 12000, 16000, 22000, 32000, 44000};
public static int sampleRate = sampleRatevalues[0];
public static final int channelInConfig = AudioFormat.CHANNEL_IN_MONO;
public static final int channelOutConfig = AudioFormat.CHANNEL_OUT_MONO;
public static final int channelNumber = 1;
Expand Down Expand Up @@ -241,6 +243,31 @@ public void onStopTrackingTouch(SeekBar seekBar) {

}
});

SeekBar sbSampleRate = findViewById(R.id.sbSampleRate);
TextView tvSampleRate = findViewById(R.id.tvSampleRate);
tvSampleRate.setText(String.format("%05d", sampleRatevalues[0]) + " Hz");
sbSampleRate.setProgress(0);
sbSampleRate.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
sampleRate = sampleRatevalues[progress];
String formattedValue = String.format("%05d", sampleRate);
tvSampleRate.setText(String.valueOf(formattedValue) + " Hz");
// Do something with the selected value
Log.d("SeekBar", "Selected value: " + sampleRate);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Optional: handle start of touch
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Optional: handle stop of touch
}
});
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions hsdemo/src/main/res/drawable/empty_circle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="24dp"
android:height="24dp" />
<stroke
android:width="2dp"
android:color="@android:color/black" />
<solid android:color="@android:color/transparent" />
</shape>
8 changes: 8 additions & 0 deletions hsdemo/src/main/res/drawable/filled_circle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="24dp"
android:height="24dp" />
<solid android:color="#000000" />
</shape>
78 changes: 63 additions & 15 deletions hsdemo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Getting Permissions"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/llGlobal" />

<LinearLayout
android:id="@+id/llGlobal"
android:layout_width="match_parent"
Expand All @@ -27,6 +17,8 @@
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:text="Recording" />

Expand Down Expand Up @@ -54,6 +46,8 @@
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:text="Recording Gain" />

Expand All @@ -77,23 +71,55 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:gravity="center_horizontal"
android:text="TextView" />
</LinearLayout>

<TextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:text="Recording Sample Rate" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<SeekBar
android:id="@+id/sbSampleRate"
style="@style/DiscreteSeekBar"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:max="5" />

<TextView
android:id="@+id/tvSampleRate"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.2"
android:gravity="center_horizontal"
android:text="08000 Hz" />
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:background="@android:color/darker_gray" />

<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:text="Replay" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -124,6 +150,8 @@
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:text="Replay Gain" />

Expand All @@ -147,15 +175,35 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:gravity="center_horizontal"
android:text="TextView" />
</LinearLayout>










<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:background="@android:color/darker_gray" />

</LinearLayout>

<TextView
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Getting Permissions"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/llGlobal" />
</androidx.constraintlayout.widget.ConstraintLayout>
6 changes: 6 additions & 0 deletions hsdemo/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
<style name="Base.Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> -->

</style>
<style name="DiscreteSeekBar" parent="Widget.AppCompat.SeekBar.Discrete">
<item name="android:thumb">@drawable/filled_circle</item>
<item name="android:tickMark">@drawable/empty_circle</item>
<item name="android:tickMarkTint">@color/black</item>
</style>
</resources>
7 changes: 6 additions & 1 deletion hsdemo/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
<style name="Base.Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>

</style>
<style name="DiscreteSeekBar" parent="Widget.AppCompat.SeekBar.Discrete">
<item name="android:thumb">@drawable/filled_circle</item>
<item name="android:tickMark">@drawable/empty_circle</item>
<item name="android:tickMarkTint">@color/black</item>
</style>
<style name="Theme.MyApplication" parent="Base.Theme.MyApplication" />
</resources>

0 comments on commit 423e1a2

Please sign in to comment.