Move dead submodules in-tree

Signed-off-by: swurl <swurl@swurl.xyz>
This commit is contained in:
swurl 2025-05-31 02:33:02 -04:00
parent c0cceff365
commit 6c655321e6
No known key found for this signature in database
GPG key ID: A5A7629F109C8FD1
4081 changed files with 1185566 additions and 45 deletions

View file

@ -0,0 +1,3 @@
### Audio Device Library
This folder contains a number of classes for working with Audio Devices. See the hello-oboe sample
for usage.

View file

@ -0,0 +1,24 @@
apply plugin: 'com.android.library'
android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 35
compileSdkVersion 35
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_18
targetCompatibility JavaVersion.VERSION_18
}
namespace 'com.google.oboe.samples.audio_device'
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.7.0'
}

View file

@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/donturner/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View file

@ -0,0 +1,2 @@
<manifest>
</manifest>

View file

@ -0,0 +1,56 @@
package com.google.oboe.samples.audio_device;
/*
* Copyright 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
/**
* Provides views for a list of audio devices. Usually used as an Adapter for a Spinner or ListView.
*/
public class AudioDeviceAdapter extends ArrayAdapter<AudioDeviceListEntry> {
public AudioDeviceAdapter(Context context) {
super(context, R.layout.audio_devices);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return getDropDownView(position, convertView, parent);
}
@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
rowView = inflater.inflate(R.layout.audio_devices, parent, false);
}
TextView deviceName = rowView.findViewById(R.id.device_name);
AudioDeviceListEntry deviceInfo = getItem(position);
deviceName.setText(deviceInfo.getName());
return rowView;
}
}

View file

@ -0,0 +1,140 @@
package com.google.oboe.samples.audio_device;
/*
* Copyright 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.media.AudioDeviceInfo;
class AudioDeviceInfoConverter {
/**
* Converts an {@link AudioDeviceInfo} object into a human readable representation
*
* @param adi The AudioDeviceInfo object to be converted to a String
* @return String containing all the information from the AudioDeviceInfo object
*/
static String toString(AudioDeviceInfo adi){
StringBuilder sb = new StringBuilder();
sb.append("Id: ");
sb.append(adi.getId());
sb.append("\nProduct name: ");
sb.append(adi.getProductName());
sb.append("\nType: ");
sb.append(typeToString(adi.getType()));
sb.append("\nIs source: ");
sb.append((adi.isSource() ? "Yes" : "No"));
sb.append("\nIs sink: ");
sb.append((adi.isSink() ? "Yes" : "No"));
sb.append("\nChannel counts: ");
int[] channelCounts = adi.getChannelCounts();
sb.append(intArrayToString(channelCounts));
sb.append("\nChannel masks: ");
int[] channelMasks = adi.getChannelMasks();
sb.append(intArrayToString(channelMasks));
sb.append("\nChannel index masks: ");
int[] channelIndexMasks = adi.getChannelIndexMasks();
sb.append(intArrayToString(channelIndexMasks));
sb.append("\nEncodings: ");
int[] encodings = adi.getEncodings();
sb.append(intArrayToString(encodings));
sb.append("\nSample Rates: ");
int[] sampleRates = adi.getSampleRates();
sb.append(intArrayToString(sampleRates));
return sb.toString();
}
/**
* Converts an integer array into a string where each int is separated by a space
*
* @param integerArray the integer array to convert to a string
* @return string containing all the integer values separated by spaces
*/
private static String intArrayToString(int[] integerArray){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < integerArray.length; i++){
sb.append(integerArray[i]);
if (i != integerArray.length -1) sb.append(" ");
}
return sb.toString();
}
/**
* Converts the value from {@link AudioDeviceInfo#getType()} into a human
* readable string
* @param type One of the {@link AudioDeviceInfo}.TYPE_* values
* e.g. AudioDeviceInfo.TYPE_BUILT_IN_SPEAKER
* @return string which describes the type of audio device
*/
static String typeToString(int type){
switch (type) {
case AudioDeviceInfo.TYPE_AUX_LINE:
return "auxiliary line-level connectors";
case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
return "Bluetooth device supporting the A2DP profile";
case AudioDeviceInfo.TYPE_BLUETOOTH_SCO:
return "Bluetooth device typically used for telephony";
case AudioDeviceInfo.TYPE_BUILTIN_EARPIECE:
return "built-in earphone speaker";
case AudioDeviceInfo.TYPE_BUILTIN_MIC:
return "built-in microphone";
case AudioDeviceInfo.TYPE_BUILTIN_SPEAKER:
return "built-in speaker";
case AudioDeviceInfo.TYPE_BUS:
return "BUS";
case AudioDeviceInfo.TYPE_DOCK:
return "DOCK";
case AudioDeviceInfo.TYPE_FM:
return "FM";
case AudioDeviceInfo.TYPE_FM_TUNER:
return "FM tuner";
case AudioDeviceInfo.TYPE_HDMI:
return "HDMI";
case AudioDeviceInfo.TYPE_HDMI_ARC:
return "HDMI audio return channel";
case AudioDeviceInfo.TYPE_IP:
return "IP";
case AudioDeviceInfo.TYPE_LINE_ANALOG:
return "line analog";
case AudioDeviceInfo.TYPE_LINE_DIGITAL:
return "line digital";
case AudioDeviceInfo.TYPE_TELEPHONY:
return "telephony";
case AudioDeviceInfo.TYPE_TV_TUNER:
return "TV tuner";
case AudioDeviceInfo.TYPE_USB_ACCESSORY:
return "USB accessory";
case AudioDeviceInfo.TYPE_USB_DEVICE:
return "USB device";
case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
return "wired headphones";
case AudioDeviceInfo.TYPE_WIRED_HEADSET:
return "wired headset";
default:
case AudioDeviceInfo.TYPE_UNKNOWN:
return "unknown";
}
}
}

View file

@ -0,0 +1,93 @@
package com.google.oboe.samples.audio_device;
/*
* Copyright 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.annotation.TargetApi;
import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import java.util.List;
import java.util.Vector;
/**
* POJO which represents basic information for an audio device.
*
* Example: id: 8, deviceName: "built-in speaker"
*/
public class AudioDeviceListEntry {
private int mId;
private String mName;
public AudioDeviceListEntry(int deviceId, String deviceName){
mId = deviceId;
mName = deviceName;
}
public int getId() {
return mId;
}
public String getName(){
return mName;
}
public String toString(){
return getName();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AudioDeviceListEntry that = (AudioDeviceListEntry) o;
if (mId != that.mId) return false;
return mName != null ? mName.equals(that.mName) : that.mName == null;
}
@Override
public int hashCode() {
int result = mId;
result = 31 * result + (mName != null ? mName.hashCode() : 0);
return result;
}
/**
* Create a list of AudioDeviceListEntry objects from a list of AudioDeviceInfo objects.
*
* @param devices A list of {@Link AudioDeviceInfo} objects
* @param directionType Only audio devices with this direction will be included in the list.
* Valid values are GET_DEVICES_ALL, GET_DEVICES_OUTPUTS and
* GET_DEVICES_INPUTS.
* @return A list of AudioDeviceListEntry objects
*/
@TargetApi(23)
static List<AudioDeviceListEntry> createListFrom(AudioDeviceInfo[] devices, int directionType){
List<AudioDeviceListEntry> listEntries = new Vector<>();
for (AudioDeviceInfo info : devices) {
if (directionType == AudioManager.GET_DEVICES_ALL ||
(directionType == AudioManager.GET_DEVICES_OUTPUTS && info.isSink()) ||
(directionType == AudioManager.GET_DEVICES_INPUTS && info.isSource())) {
listEntries.add(new AudioDeviceListEntry(info.getId(), info.getProductName() + " " +
AudioDeviceInfoConverter.typeToString(info.getType())));
}
}
return listEntries;
}
}

View file

@ -0,0 +1,117 @@
package com.google.oboe.samples.audio_device;
/*
* Copyright 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources.Theme;
import android.media.AudioDeviceCallback;
import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.util.AttributeSet;
import android.widget.Spinner;
import java.util.List;
public class AudioDeviceSpinner extends Spinner {
private static final int AUTO_SELECT_DEVICE_ID = 0;
private static final String TAG = AudioDeviceSpinner.class.getName();
private int mDirectionType;
private AudioDeviceAdapter mDeviceAdapter;
private AudioManager mAudioManager;
public AudioDeviceSpinner(Context context){
super(context);
setup(context);
}
public AudioDeviceSpinner(Context context, int mode){
super(context, mode);
setup(context);
}
public AudioDeviceSpinner(Context context, AttributeSet attrs){
super(context, attrs);
setup(context);
}
public AudioDeviceSpinner(Context context, AttributeSet attrs, int defStyleAttr){
super(context, attrs, defStyleAttr);
setup(context);
}
public AudioDeviceSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode){
super(context, attrs, defStyleAttr, mode);
setup(context);
}
public AudioDeviceSpinner(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes, int mode){
super(context, attrs, defStyleAttr, defStyleRes, mode);
setup(context);
}
public AudioDeviceSpinner(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes, int mode, Theme popupTheme){
super(context, attrs, defStyleAttr, defStyleRes, mode, popupTheme);
setup(context);
}
private void setup(Context context){
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mDeviceAdapter = new AudioDeviceAdapter(context);
setAdapter(mDeviceAdapter);
// Add a default entry to the list and select it
mDeviceAdapter.add(new AudioDeviceListEntry(AUTO_SELECT_DEVICE_ID,
context.getString(R.string.auto_select)));
setSelection(0);
}
@TargetApi(23)
public void setDirectionType(int directionType){
this.mDirectionType = directionType;
setupAudioDeviceCallback();
}
@TargetApi(23)
private void setupAudioDeviceCallback(){
// Note that we will immediately receive a call to onDevicesAdded with the list of
// devices which are currently connected.
mAudioManager.registerAudioDeviceCallback(new AudioDeviceCallback() {
@Override
public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
List<AudioDeviceListEntry> deviceList =
AudioDeviceListEntry.createListFrom(addedDevices, mDirectionType);
if (deviceList.size() > 0){
mDeviceAdapter.addAll(deviceList);
}
}
public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
List<AudioDeviceListEntry> deviceList =
AudioDeviceListEntry.createListFrom(removedDevices, mDirectionType);
for (AudioDeviceListEntry entry : deviceList){
mDeviceAdapter.remove(entry);
}
}
}, null);
}
}

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2017 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/device_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/default_padding"
android:text="@string/device_name"/>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="default_padding">16dp</dimen>
</resources>

View file

@ -0,0 +1,4 @@
<resources>
<string name="device_name">Device Name</string>
<string name="auto_select">Auto select</string>
</resources>