Skip to content

Commit

Permalink
OboeTester: add checkbox for enabling SCO
Browse files Browse the repository at this point in the history
  • Loading branch information
philburk committed Jun 10, 2020
1 parent 3947bd0 commit 16a9264
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package com.google.sample.oboe.manualtest;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Point;
Expand Down Expand Up @@ -55,6 +57,7 @@ public class MainActivity extends Activity {
protected TextView mDeviceView;
private TextView mVersionTextView;
private TextView mBuildTextView;
private TextView mBluetoothScoStatusView;
private Bundle mBundleFromIntent;

@Override
Expand Down Expand Up @@ -100,6 +103,20 @@ public void onNothingSelected(AdapterView<?> adapterView) {
mBuildTextView = (TextView) findViewById(R.id.text_build_info);
mBuildTextView.setText(Build.DISPLAY);

mBluetoothScoStatusView = (TextView) findViewById(R.id.textBluetoothScoStatus);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
if (state == AudioManager.SCO_AUDIO_STATE_CONNECTING) {
mBluetoothScoStatusView.setText("CONNECTING");
} else if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
mBluetoothScoStatusView.setText("CONNECTED");
} else if (state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) {
mBluetoothScoStatusView.setText("DISCONNECTED");
}
}
}, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));

saveIntentBundleForLaterProcessing(getIntent());
}
Expand Down Expand Up @@ -252,6 +269,16 @@ public void onSetSpeakerphoneOn(View view) {
myAudioMgr.setSpeakerphoneOn(enabled);
}

public void onStartStopBluetoothSco(View view) {
CheckBox checkBox = (CheckBox) view;
AudioManager myAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (checkBox.isChecked()) {
myAudioMgr.startBluetoothSco();
} else {
myAudioMgr.stopBluetoothSco();
}
}

public void onEnableWorkarounds(View view) {
CheckBox checkBox = (CheckBox) view;
boolean enabled = checkBox.isChecked();
Expand Down
33 changes: 30 additions & 3 deletions apps/OboeTester/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,37 @@
android:layout_marginTop="6dp"
android:checked="false"
android:onClick="onSetSpeakerphoneOn"
android:text="call setSpeakerphoneOn()"
android:text="setSpeakerphoneOn/Off()"
app:layout_constraintStart_toStartOf="@+id/useCallback"
app:layout_constraintTop_toBottomOf="@+id/useCallback" />

<LinearLayout
android:id="@+id/layoutBluetoothSco"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="@+id/setSpeakerphoneOn"
app:layout_constraintTop_toBottomOf="@+id/setSpeakerphoneOn"
>
<CheckBox
android:id="@+id/setBluetoothScoOn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:checked="false"
android:onClick="onStartStopBluetoothSco"
android:text="start/stopBluetoothSco()"
/>

<TextView
android:id="@+id/textBluetoothScoStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="12sp"
android:text="\?" />
</LinearLayout>

<CheckBox
android:id="@+id/boxEnableWorkarounds"
android:layout_width="wrap_content"
Expand All @@ -162,8 +189,8 @@
android:checked="false"
android:onClick="onEnableWorkarounds"
android:text="enable Oboe workarounds"
app:layout_constraintStart_toStartOf="@+id/setSpeakerphoneOn"
app:layout_constraintTop_toBottomOf="@+id/setSpeakerphoneOn" />
app:layout_constraintStart_toStartOf="@+id/layoutBluetoothSco"
app:layout_constraintTop_toBottomOf="@+id/layoutBluetoothSco" />


<TextView
Expand Down

0 comments on commit 16a9264

Please sign in to comment.