diff options
Diffstat (limited to 'java/com/android/incallui/audioroute')
3 files changed, 82 insertions, 12 deletions
diff --git a/java/com/android/incallui/audioroute/AudioRouteSelectorDialogFragment.java b/java/com/android/incallui/audioroute/AudioRouteSelectorDialogFragment.java index d481f4339..79cae098d 100644 --- a/java/com/android/incallui/audioroute/AudioRouteSelectorDialogFragment.java +++ b/java/com/android/incallui/audioroute/AudioRouteSelectorDialogFragment.java @@ -17,6 +17,7 @@ package com.android.incallui.audioroute; import android.app.Dialog; +import android.bluetooth.BluetoothDevice; import android.content.Context; import android.content.DialogInterface; import android.content.res.ColorStateList; @@ -29,9 +30,12 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.widget.LinearLayout; import android.widget.TextView; import com.android.dialer.common.FragmentUtils; import com.android.dialer.common.LogUtil; +import com.android.incallui.audiomode.BluetoothDeviceProviderComponent; +import java.util.Set; /** Shows picker for audio routes */ public class AudioRouteSelectorDialogFragment extends BottomSheetDialogFragment { @@ -75,10 +79,22 @@ public class AudioRouteSelectorDialogFragment extends BottomSheetDialogFragment View view = layoutInflater.inflate(R.layout.audioroute_selector, viewGroup, false); CallAudioState audioState = getArguments().getParcelable(ARG_AUDIO_STATE); - initItem( - (TextView) view.findViewById(R.id.audioroute_bluetooth), - CallAudioState.ROUTE_BLUETOOTH, - audioState); + Set<BluetoothDevice> bluetoothDeviceSet = + BluetoothDeviceProviderComponent.get(getContext()) + .bluetoothDeviceProvider() + .getConnectedBluetoothDeviceSet(); + for (BluetoothDevice device : bluetoothDeviceSet) { + boolean selected = + (audioState.getRoute() == CallAudioState.ROUTE_BLUETOOTH) + && (bluetoothDeviceSet.size() == 1 + || device.equals( + BluetoothDeviceProviderComponent.get(getContext()) + .bluetoothDeviceProvider() + .getActiveBluetoothDevice())); + TextView textView = createBluetoothItem(device, selected); + ((LinearLayout) view).addView(textView, 0); + } + initItem( (TextView) view.findViewById(R.id.audioroute_speaker), CallAudioState.ROUTE_SPEAKER, @@ -121,4 +137,30 @@ public class AudioRouteSelectorDialogFragment extends BottomSheetDialogFragment .onAudioRouteSelected(itemRoute); }); } + + private TextView createBluetoothItem(BluetoothDevice bluetoothDevice, boolean selected) { + int selectedColor = getResources().getColor(R.color.dialer_theme_color); + TextView textView = + (TextView) getLayoutInflater().inflate(R.layout.audioroute_item, null, false); + textView.setText(bluetoothDevice.getName()); + if (selected) { + textView.setTextColor(selectedColor); + textView.setCompoundDrawableTintList(ColorStateList.valueOf(selectedColor)); + textView.setCompoundDrawableTintMode(Mode.SRC_ATOP); + } + textView.setOnClickListener( + (v) -> { + dismiss(); + // Set Bluetooth audio route + FragmentUtils.getParentUnsafe( + AudioRouteSelectorDialogFragment.this, AudioRouteSelectorPresenter.class) + .onAudioRouteSelected(CallAudioState.ROUTE_BLUETOOTH); + // Set active Bluetooth device + BluetoothDeviceProviderComponent.get(getContext()) + .bluetoothDeviceProvider() + .setActiveBluetoothDevice(bluetoothDevice); + }); + + return textView; + } } diff --git a/java/com/android/incallui/audioroute/res/layout/audioroute_item.xml b/java/com/android/incallui/audioroute/res/layout/audioroute_item.xml new file mode 100644 index 000000000..66c83f67e --- /dev/null +++ b/java/com/android/incallui/audioroute/res/layout/audioroute_item.xml @@ -0,0 +1,21 @@ +<!-- +~ Copyright (C) 2018 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" + style="@style/AudioRouteItem" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:drawableStart="@drawable/quantum_ic_bluetooth_audio_vd_theme_24" + android:drawableTint="@color/material_grey_600"/>
\ No newline at end of file diff --git a/java/com/android/incallui/audioroute/res/layout/audioroute_selector.xml b/java/com/android/incallui/audioroute/res/layout/audioroute_selector.xml index ef2220e8f..145101dd1 100644 --- a/java/com/android/incallui/audioroute/res/layout/audioroute_selector.xml +++ b/java/com/android/incallui/audioroute/res/layout/audioroute_selector.xml @@ -1,4 +1,18 @@ -<?xml version="1.0" encoding="utf-8"?> +<!-- +~ Copyright (C) 2018 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 +--> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" @@ -6,13 +20,6 @@ android:orientation="vertical" tools:layout_gravity="bottom"> <TextView - android:id="@+id/audioroute_bluetooth" - style="@style/AudioRouteItem" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:drawableStart="@drawable/quantum_ic_bluetooth_audio_grey600_24" - android:text="@string/audioroute_bluetooth"/> - <TextView android:id="@+id/audioroute_speaker" style="@style/AudioRouteItem" android:layout_width="match_parent" |