Merge "[Audiosharing] Refine main sharing dialog." into main
This commit is contained in:
BIN
res/drawable/audio_sharing_guidance.png
Normal file
BIN
res/drawable/audio_sharing_guidance.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
@@ -19,38 +19,64 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="24dp"
|
android:orientation="vertical"
|
||||||
android:orientation="vertical">
|
android:paddingHorizontal="?android:dialogPreferredPadding"
|
||||||
|
android:paddingBottom="?android:dialogPreferredPadding">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/DeviceAudioSharingText"
|
|
||||||
android:id="@+id/share_audio_subtitle1"
|
android:id="@+id/share_audio_subtitle1"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:layout_gravity="center"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
style="@style/DeviceAudioSharingText"
|
style="@style/DeviceAudioSharingText"
|
||||||
android:id="@+id/share_audio_subtitle2"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:layout_gravity="center"/>
|
|
||||||
|
|
||||||
<com.android.internal.widget.RecyclerView
|
|
||||||
android:visibility="visible"
|
|
||||||
android:id="@+id/btn_list"
|
|
||||||
android:nestedScrollingEnabled="false"
|
|
||||||
android:overScrollMode="never"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/cancel_btn"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:text="@string/cancel"/>
|
android:paddingBottom="14dp"
|
||||||
|
android:textFontWeight="500"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/share_audio_subtitle2"
|
||||||
|
style="@style/DeviceAudioSharingText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:paddingBottom="24dp"
|
||||||
|
android:textFontWeight="400" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/share_audio_guidance"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:src="@drawable/audio_sharing_guidance"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<com.android.internal.widget.RecyclerView
|
||||||
|
android:id="@+id/btn_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:nestedScrollingEnabled="false"
|
||||||
|
android:overScrollMode="never"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/share_btn"
|
||||||
|
style="@style/SettingsLibActionButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:background="@drawable/audio_sharing_rounded_bg_ripple"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/cancel_btn"
|
||||||
|
style="@style/SettingsLibActionButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:background="@drawable/audio_sharing_rounded_bg_ripple"
|
||||||
|
android:text="Not now"
|
||||||
|
android:visibility="gone" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@@ -22,6 +22,7 @@ import android.os.Bundle;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
@@ -33,8 +34,10 @@ import com.android.internal.widget.RecyclerView;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Locale;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
|
public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
|
||||||
private static final String TAG = "AudioSharingDialog";
|
private static final String TAG = "AudioSharingDialog";
|
||||||
@@ -54,8 +57,6 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
|
|||||||
|
|
||||||
private static DialogEventListener sListener;
|
private static DialogEventListener sListener;
|
||||||
|
|
||||||
private View mRootView;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
return SettingsEnums.DIALOG_START_AUDIO_SHARING;
|
return SettingsEnums.DIALOG_START_AUDIO_SHARING;
|
||||||
@@ -90,40 +91,62 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
|
|||||||
ArrayList<AudioSharingDeviceItem> deviceItems =
|
ArrayList<AudioSharingDeviceItem> deviceItems =
|
||||||
arguments.getParcelableArrayList(BUNDLE_KEY_DEVICE_ITEMS);
|
arguments.getParcelableArrayList(BUNDLE_KEY_DEVICE_ITEMS);
|
||||||
final AlertDialog.Builder builder =
|
final AlertDialog.Builder builder =
|
||||||
new AlertDialog.Builder(getActivity()).setTitle("Share audio").setCancelable(false);
|
new AlertDialog.Builder(getActivity()).setCancelable(false);
|
||||||
mRootView =
|
LayoutInflater inflater = LayoutInflater.from(builder.getContext());
|
||||||
LayoutInflater.from(builder.getContext())
|
View customTitle = inflater.inflate(R.layout.dialog_custom_title_audio_sharing, null);
|
||||||
.inflate(R.layout.dialog_audio_sharing, /* parent= */ null);
|
ImageView icon = customTitle.findViewById(R.id.title_icon);
|
||||||
TextView subTitle1 = mRootView.findViewById(R.id.share_audio_subtitle1);
|
icon.setImageResource(R.drawable.ic_bt_audio_sharing);
|
||||||
TextView subTitle2 = mRootView.findViewById(R.id.share_audio_subtitle2);
|
TextView title = customTitle.findViewById(R.id.title_text);
|
||||||
|
View rootView = inflater.inflate(R.layout.dialog_audio_sharing, /* parent= */ null);
|
||||||
|
TextView subTitle1 = rootView.findViewById(R.id.share_audio_subtitle1);
|
||||||
|
TextView subTitle2 = rootView.findViewById(R.id.share_audio_subtitle2);
|
||||||
|
RecyclerView recyclerView = rootView.findViewById(R.id.btn_list);
|
||||||
|
Button shareBtn = rootView.findViewById(R.id.share_btn);
|
||||||
|
Button cancelBtn = rootView.findViewById(R.id.cancel_btn);
|
||||||
if (deviceItems.isEmpty()) {
|
if (deviceItems.isEmpty()) {
|
||||||
subTitle1.setVisibility(View.INVISIBLE);
|
title.setText("Share your audio");
|
||||||
subTitle2.setText(
|
subTitle2.setText(
|
||||||
"To start sharing audio, connect additional headphones that support LE audio");
|
"To start sharing audio, "
|
||||||
} else {
|
+ "connect two pairs of headphones that support LE Audio");
|
||||||
|
ImageView image = rootView.findViewById(R.id.share_audio_guidance);
|
||||||
|
image.setVisibility(View.VISIBLE);
|
||||||
|
builder.setNegativeButton("Close", null);
|
||||||
|
} else if (deviceItems.size() == 1) {
|
||||||
|
title.setText("Share your audio");
|
||||||
subTitle1.setText(
|
subTitle1.setText(
|
||||||
String.format(
|
deviceItems.stream()
|
||||||
Locale.US,
|
.map(AudioSharingDeviceItem::getName)
|
||||||
"%d additional device%s connected",
|
.collect(Collectors.joining(" and ")));
|
||||||
deviceItems.size(),
|
|
||||||
deviceItems.size() > 1 ? "" : "s"));
|
|
||||||
subTitle2.setText(
|
subTitle2.setText(
|
||||||
"The headphones you share audio with will hear videos and music playing on this"
|
"This device's music and videos will play on both pairs of headphones");
|
||||||
+ " phone");
|
shareBtn.setText("Share audio");
|
||||||
|
shareBtn.setOnClickListener(
|
||||||
|
v -> {
|
||||||
|
sListener.onItemClick(Iterables.getOnlyElement(deviceItems));
|
||||||
|
dismiss();
|
||||||
|
});
|
||||||
|
cancelBtn.setOnClickListener(v -> dismiss());
|
||||||
|
subTitle1.setVisibility(View.VISIBLE);
|
||||||
|
shareBtn.setVisibility(View.VISIBLE);
|
||||||
|
cancelBtn.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
title.setText("Share audio with another device");
|
||||||
|
subTitle2.setText(
|
||||||
|
"This device's music and videos will play on the headphones you connect");
|
||||||
|
recyclerView.setAdapter(
|
||||||
|
new AudioSharingDeviceAdapter(
|
||||||
|
deviceItems,
|
||||||
|
(AudioSharingDeviceItem item) -> {
|
||||||
|
sListener.onItemClick(item);
|
||||||
|
dismiss();
|
||||||
|
}));
|
||||||
|
recyclerView.setLayoutManager(
|
||||||
|
new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
|
||||||
|
recyclerView.setVisibility(View.VISIBLE);
|
||||||
|
cancelBtn.setOnClickListener(v -> dismiss());
|
||||||
|
cancelBtn.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
RecyclerView recyclerView = mRootView.findViewById(R.id.btn_list);
|
AlertDialog dialog = builder.setCustomTitle(customTitle).setView(rootView).create();
|
||||||
recyclerView.setAdapter(
|
|
||||||
new AudioSharingDeviceAdapter(
|
|
||||||
deviceItems,
|
|
||||||
(AudioSharingDeviceItem item) -> {
|
|
||||||
sListener.onItemClick(item);
|
|
||||||
dismiss();
|
|
||||||
}));
|
|
||||||
recyclerView.setLayoutManager(
|
|
||||||
new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
|
|
||||||
Button cancelBtn = mRootView.findViewById(R.id.cancel_btn);
|
|
||||||
cancelBtn.setOnClickListener(v -> dismiss());
|
|
||||||
AlertDialog dialog = builder.setView(mRootView).create();
|
|
||||||
dialog.setCanceledOnTouchOutside(false);
|
dialog.setCanceledOnTouchOutside(false);
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,229 @@
|
|||||||
|
/*
|
||||||
|
* 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 static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothStatusCodes;
|
||||||
|
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||||
|
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||||
|
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||||
|
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.flags.Flags;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadow.api.Shadow;
|
||||||
|
import org.robolectric.shadows.androidx.fragment.FragmentController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(
|
||||||
|
shadows = {
|
||||||
|
ShadowAlertDialogCompat.class,
|
||||||
|
ShadowBluetoothAdapter.class,
|
||||||
|
})
|
||||||
|
public class AudioSharingDialogFragmentTest {
|
||||||
|
|
||||||
|
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||||
|
|
||||||
|
private static final String TEST_DEVICE_NAME1 = "test1";
|
||||||
|
|
||||||
|
private static final String TEST_DEVICE_NAME2 = "test2";
|
||||||
|
private static final String TEST_DEVICE_NAME3 = "test3";
|
||||||
|
private static final AudioSharingDeviceItem TEST_DEVICE_ITEM1 =
|
||||||
|
new AudioSharingDeviceItem(TEST_DEVICE_NAME1, /* groupId= */ 1, /* isActive= */ false);
|
||||||
|
private static final AudioSharingDeviceItem TEST_DEVICE_ITEM2 =
|
||||||
|
new AudioSharingDeviceItem(TEST_DEVICE_NAME2, /* groupId= */ 2, /* isActive= */ false);
|
||||||
|
private static final AudioSharingDeviceItem TEST_DEVICE_ITEM3 =
|
||||||
|
new AudioSharingDeviceItem(TEST_DEVICE_NAME3, /* groupId= */ 3, /* isActive= */ false);
|
||||||
|
|
||||||
|
private Fragment mParent;
|
||||||
|
private AudioSharingDialogFragment mFragment;
|
||||||
|
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||||
|
mShadowBluetoothAdapter.setEnabled(true);
|
||||||
|
mShadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported(
|
||||||
|
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||||
|
mShadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
|
||||||
|
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||||
|
mFragment = new AudioSharingDialogFragment();
|
||||||
|
mParent = new Fragment();
|
||||||
|
FragmentController.setupFragment(
|
||||||
|
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
ShadowAlertDialogCompat.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsDisabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||||
|
public void onCreateDialog_flagOff_dialogNotExist() {
|
||||||
|
mFragment.show(mParent, new ArrayList<>(), (item) -> {});
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
assertThat(dialog).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||||
|
public void onCreateDialog_flagOn_noConnectedDevice() {
|
||||||
|
mFragment.show(mParent, new ArrayList<>(), (item) -> {});
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||||
|
View rootView = shadowDialog.getView();
|
||||||
|
TextView subtitle1 = rootView.findViewById(R.id.share_audio_subtitle1);
|
||||||
|
ImageView guidance = rootView.findViewById(R.id.share_audio_guidance);
|
||||||
|
Button shareBtn = rootView.findViewById(R.id.share_btn);
|
||||||
|
assertThat(dialog.isShowing()).isTrue();
|
||||||
|
assertThat(subtitle1.getVisibility()).isEqualTo(View.GONE);
|
||||||
|
assertThat(guidance.getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
|
assertThat(shareBtn.getVisibility()).isEqualTo(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||||
|
public void onCreateDialog_noConnectedDevice_dialogDismiss() {
|
||||||
|
mFragment.show(mParent, new ArrayList<>(), (item) -> {});
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
dialog.findViewById(android.R.id.button2).performClick();
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
assertThat(dialog.isShowing()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||||
|
public void onCreateDialog_flagOn_singleConnectedDevice() {
|
||||||
|
ArrayList<AudioSharingDeviceItem> list = new ArrayList<>();
|
||||||
|
list.add(TEST_DEVICE_ITEM1);
|
||||||
|
mFragment.show(mParent, list, (item) -> {});
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||||
|
View rootView = shadowDialog.getView();
|
||||||
|
TextView subtitle1 = rootView.findViewById(R.id.share_audio_subtitle1);
|
||||||
|
ImageView guidance = rootView.findViewById(R.id.share_audio_guidance);
|
||||||
|
Button shareBtn = rootView.findViewById(R.id.share_btn);
|
||||||
|
assertThat(dialog.isShowing()).isTrue();
|
||||||
|
assertThat(subtitle1.getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
|
assertThat(TEST_DEVICE_NAME1).isEqualTo(subtitle1.getText());
|
||||||
|
assertThat(guidance.getVisibility()).isEqualTo(View.GONE);
|
||||||
|
assertThat(shareBtn.getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||||
|
public void onCreateDialog_singleConnectedDevice_dialogDismiss() {
|
||||||
|
mFragment.show(mParent, new ArrayList<>(), (item) -> {});
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||||
|
View rootView = shadowDialog.getView();
|
||||||
|
rootView.findViewById(R.id.cancel_btn).performClick();
|
||||||
|
assertThat(dialog.isShowing()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||||
|
public void onCreateDialog_singleConnectedDevice_shareClicked() {
|
||||||
|
AtomicBoolean isShareBtnClicked = new AtomicBoolean(false);
|
||||||
|
mFragment.show(
|
||||||
|
mParent,
|
||||||
|
new ArrayList<>(),
|
||||||
|
(item) -> {
|
||||||
|
isShareBtnClicked.set(true);
|
||||||
|
});
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||||
|
View rootView = shadowDialog.getView();
|
||||||
|
rootView.findViewById(R.id.share_btn).performClick();
|
||||||
|
assertThat(dialog.isShowing()).isFalse();
|
||||||
|
assertThat(isShareBtnClicked.get()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||||
|
public void onCreateDialog_flagOn_multipleConnectedDevice() {
|
||||||
|
ArrayList<AudioSharingDeviceItem> list = new ArrayList<>();
|
||||||
|
list.add(TEST_DEVICE_ITEM1);
|
||||||
|
list.add(TEST_DEVICE_ITEM2);
|
||||||
|
list.add(TEST_DEVICE_ITEM3);
|
||||||
|
mFragment.show(mParent, list, (item) -> {});
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||||
|
View rootView = shadowDialog.getView();
|
||||||
|
TextView subtitle1 = rootView.findViewById(R.id.share_audio_subtitle1);
|
||||||
|
ImageView guidance = rootView.findViewById(R.id.share_audio_guidance);
|
||||||
|
Button shareBtn = rootView.findViewById(R.id.share_btn);
|
||||||
|
assertThat(dialog.isShowing()).isTrue();
|
||||||
|
assertThat(subtitle1.getVisibility()).isEqualTo(View.GONE);
|
||||||
|
assertThat(guidance.getVisibility()).isEqualTo(View.GONE);
|
||||||
|
assertThat(shareBtn.getVisibility()).isEqualTo(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||||
|
public void onCreateDialog_multipleConnectedDevice_dialogDismiss() {
|
||||||
|
ArrayList<AudioSharingDeviceItem> list = new ArrayList<>();
|
||||||
|
list.add(TEST_DEVICE_ITEM1);
|
||||||
|
list.add(TEST_DEVICE_ITEM2);
|
||||||
|
list.add(TEST_DEVICE_ITEM3);
|
||||||
|
mFragment.show(mParent, list, (item) -> {});
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||||
|
View rootView = shadowDialog.getView();
|
||||||
|
rootView.findViewById(R.id.cancel_btn).performClick();
|
||||||
|
assertThat(dialog.isShowing()).isFalse();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user