[Audiosharing] Add calls and alarms device picker when sharing.
Flagged with enable_le_audio_sharing Bug: 305620450 Test: Manual Change-Id: I211bbd83e29a1ea865c3e368f0fcacf3a98255e9
This commit is contained in:
32
res/drawable/ic_audio_calls_and_alarms.xml
Normal file
32
res/drawable/ic_audio_calls_and_alarms.xml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0"
|
||||||
|
android:tint="?android:attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:pathData="M3,15V9H7L12,4V20L7,15H3ZM10,15.17V8.83L7.83,11H5V13H7.83L10,15.17Z"
|
||||||
|
android:fillType="evenOdd"
|
||||||
|
android:fillColor="?android:attr/colorPrimary"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M16.5,12C16.5,10.23 15.48,8.71 14,7.97V16.02C15.48,15.29 16.5,13.77 16.5,12Z"
|
||||||
|
android:fillColor="?android:attr/colorPrimary"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M14,3.23V5.29C16.89,6.15 19,8.83 19,12C19,15.17 16.89,17.85 14,18.71V20.77C18.01,19.86 21,16.28 21,12C21,7.72 18.01,4.14 14,3.23Z"
|
||||||
|
android:fillColor="?android:attr/colorPrimary"/>
|
||||||
|
</vector>
|
@@ -292,6 +292,8 @@
|
|||||||
<string name="audio_sharing_title">Audio sharing</string>
|
<string name="audio_sharing_title">Audio sharing</string>
|
||||||
<!-- Title for audio sharing primary switch [CHAR LIMIT=none]-->
|
<!-- Title for audio sharing primary switch [CHAR LIMIT=none]-->
|
||||||
<string name="audio_sharing_switch_title">Share audio</string>
|
<string name="audio_sharing_switch_title">Share audio</string>
|
||||||
|
<!-- Title for calls and alarms device on audio sharing page [CHAR LIMIT=none]-->
|
||||||
|
<string name="calls_and_alarms_device_title">Calls and alarms</string>
|
||||||
|
|
||||||
<!-- Date & time settings screen title -->
|
<!-- Date & time settings screen title -->
|
||||||
<string name="date_and_time">Date & time</string>
|
<string name="date_and_time">Date & time</string>
|
||||||
|
@@ -19,4 +19,10 @@
|
|||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
android:title="@string/audio_sharing_title">
|
android:title="@string/audio_sharing_title">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="calls_and_alarms"
|
||||||
|
android:title="@string/calls_and_alarms_device_title"
|
||||||
|
android:icon="@drawable/ic_audio_calls_and_alarms"
|
||||||
|
settings:controller="com.android.settings.connecteddevice.audiosharing.CallsAndAlarmsPreferenceController"
|
||||||
|
android:summary=""/>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.connecteddevice.audiosharing;
|
package com.android.settings.connecteddevice.audiosharing;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
@@ -36,8 +37,7 @@ public class AudioSharingDashboardFragment extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
// TODO: update category id.
|
return SettingsEnums.AUDIO_SHARING_SETTINGS;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,6 +63,7 @@ public class AudioSharingDashboardFragment extends DashboardFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
|
use(CallsAndAlarmsPreferenceController.class).init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.connecteddevice.audiosharing;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
|
import com.android.settings.flags.Flags;
|
||||||
|
|
||||||
|
/** Provides a dialog to choose the active device for calls and alarms. */
|
||||||
|
public class CallsAndAlarmsDialogFragment extends InstrumentedDialogFragment {
|
||||||
|
private static final String TAG = "CallsAndAlarmsDialog";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.DIALOG_AUDIO_SHARING_SWITCH_ACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the {@link CallsAndAlarmsDialogFragment} dialog.
|
||||||
|
*
|
||||||
|
* @param host The Fragment this dialog will be hosted.
|
||||||
|
*/
|
||||||
|
public static void show(Fragment host) {
|
||||||
|
if (!Flags.enableLeAudioSharing()) return;
|
||||||
|
final FragmentManager manager = host.getChildFragmentManager();
|
||||||
|
if (manager.findFragmentByTag(TAG) == null) {
|
||||||
|
final CallsAndAlarmsDialogFragment dialog = new CallsAndAlarmsDialogFragment();
|
||||||
|
dialog.show(manager, TAG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
// TODO: use real device names
|
||||||
|
String[] choices = {"Buds 1", "Buds 2"};
|
||||||
|
AlertDialog.Builder builder =
|
||||||
|
new AlertDialog.Builder(getActivity())
|
||||||
|
.setTitle(R.string.calls_and_alarms_device_title)
|
||||||
|
.setSingleChoiceItems(
|
||||||
|
choices,
|
||||||
|
0, // TODO: set to current active device.
|
||||||
|
(dialog, which) -> {
|
||||||
|
// TODO: set device to active device for calls and alarms.
|
||||||
|
});
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.connecteddevice.audiosharing;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.flags.Flags;
|
||||||
|
|
||||||
|
/** PreferenceController to control the dialog to choose the active device for calls and alarms */
|
||||||
|
public class CallsAndAlarmsPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
private static final String TAG = "CallsAndAlarmsPreferenceController";
|
||||||
|
|
||||||
|
private static final String PREF_KEY = "calls_and_alarms";
|
||||||
|
|
||||||
|
private Preference mPreference;
|
||||||
|
private DashboardFragment mFragment;
|
||||||
|
|
||||||
|
public CallsAndAlarmsPreferenceController(Context context) {
|
||||||
|
super(context, PREF_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return Flags.enableLeAudioSharing() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return PREF_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
mPreference.setOnPreferenceClickListener(
|
||||||
|
preference -> {
|
||||||
|
if (mFragment != null) {
|
||||||
|
CallsAndAlarmsDialogFragment.show(mFragment);
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "Dialog fail to show due to null host.");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the controller.
|
||||||
|
*
|
||||||
|
* @param fragment The fragment to host the {@link CallsAndAlarmsDialogFragment} dialog.
|
||||||
|
*/
|
||||||
|
public void init(DashboardFragment fragment) {
|
||||||
|
this.mFragment = fragment;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user