diff --git a/res/layout-land/bluetooth_audio_streams_qr_code.xml b/res/layout-land/bluetooth_audio_streams_qr_code.xml index 17151979074..432d75e69d6 100644 --- a/res/layout-land/bluetooth_audio_streams_qr_code.xml +++ b/res/layout-land/bluetooth_audio_streams_qr_code.xml @@ -15,48 +15,48 @@ ~ limitations under the License. --> - + android:layout_height="wrap_content"> - - - + android:layout_height="match_parent" + android:orientation="horizontal" + android:padding="25dp" + android:gravity="center"> + + + + + + + + + - - - - - - - - - + \ No newline at end of file diff --git a/res/layout-land/qrcode_scanner_fragment.xml b/res/layout-land/qrcode_scanner_fragment.xml index 0e563e32f6c..daad35d0d7f 100644 --- a/res/layout-land/qrcode_scanner_fragment.xml +++ b/res/layout-land/qrcode_scanner_fragment.xml @@ -15,60 +15,45 @@ limitations under the License. --> - + android:layout_height="wrap_content"> - - - - - - - - + android:orientation="horizontal" + android:paddingTop="@dimen/audio_streams_qrcode_scanner_fragment_padding"> + + + android:orientation="vertical" + android:layout_weight="1" + android:gravity="center"> + + + - - - + diff --git a/res/layout/bluetooth_audio_streams_qr_code.xml b/res/layout/bluetooth_audio_streams_qr_code.xml index ae2d4e0764b..ab61f50e836 100644 --- a/res/layout/bluetooth_audio_streams_qr_code.xml +++ b/res/layout/bluetooth_audio_streams_qr_code.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> - @@ -23,10 +23,9 @@ + android:textColor="?android:attr/textColorPrimary" /> - + + - - - - - + android:textSize="15sp" + android:textColor="?android:attr/textColorPrimary" + android:gravity="center" /> - \ No newline at end of file + \ No newline at end of file diff --git a/res/layout/qrcode_scanner_fragment.xml b/res/layout/qrcode_scanner_fragment.xml index 72049a4b2e7..1526cf80fea 100644 --- a/res/layout/qrcode_scanner_fragment.xml +++ b/res/layout/qrcode_scanner_fragment.xml @@ -15,69 +15,41 @@ limitations under the License. --> - + android:layout_height="wrap_content"> - + + - - - + android:layout_margin="40dp" /> - - - - - + android:focusable="true" /> - + android:visibility="gone"/> - - + diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 5158ed692dd..c6bfc67bbd7 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -500,7 +500,9 @@ 16dp 264dp + 300dp 30dp + 16dp 136dp diff --git a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelper.java b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelper.java index 215b677aa2c..c219e0b6de3 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelper.java +++ b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelper.java @@ -28,10 +28,13 @@ import android.bluetooth.BluetoothLeBroadcastMetadata; import android.bluetooth.BluetoothLeBroadcastReceiveState; import android.content.Context; import android.content.Intent; +import android.content.res.Configuration; import android.util.Log; import androidx.annotation.VisibleForTesting; +import androidx.fragment.app.FragmentActivity; +import com.android.settings.R; import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils; import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; @@ -40,6 +43,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.utils.ThreadUtils; +import com.google.android.material.appbar.AppBarLayout; import com.google.common.base.Strings; import java.util.ArrayList; @@ -346,4 +350,16 @@ public class AudioStreamsHelper { intent.putParcelableArrayListExtra(DEVICES, new ArrayList<>(devices)); context.startService(intent); } + + static void configureAppBarByOrientation(@Nullable FragmentActivity activity) { + if (activity != null) { + AppBarLayout appBarLayout = activity.findViewById(R.id.app_bar); + if (appBarLayout != null) { + boolean canAppBarExpand = + activity.getResources().getConfiguration().orientation + == Configuration.ORIENTATION_PORTRAIT; + appBarLayout.setExpanded(canAppBarExpand); + } + } + } } diff --git a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsQrCodeFragment.java b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsQrCodeFragment.java index 47f9c75514e..3c362c00d80 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsQrCodeFragment.java +++ b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsQrCodeFragment.java @@ -61,6 +61,8 @@ public class AudioStreamsQrCodeFragment extends InstrumentedFragment { @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + // Collapse or expand the app bar based on orientation for better display the qr code image. + AudioStreamsHelper.configureAppBarByOrientation(getActivity()); var unused = ThreadUtils.postOnBackgroundThread( () -> { BluetoothLeBroadcastMetadata broadcastMetadata = getBroadcastMetadata(); diff --git a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsQrCodeScanFragment.java b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsQrCodeScanFragment.java index 8df4317e9f7..76854a41113 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsQrCodeScanFragment.java +++ b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsQrCodeScanFragment.java @@ -116,6 +116,8 @@ public class AudioStreamsQrCodeScanFragment extends InstrumentedFragment @Override public final View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + // Collapse or expand the app bar based on orientation for better display the qr camera. + AudioStreamsHelper.configureAppBarByOrientation(getActivity()); return inflater.inflate( R.layout.qrcode_scanner_fragment, container, /* attachToRoot */ false); } diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelperTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelperTest.java index b91866bf326..42667982eda 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelperTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelperTest.java @@ -16,6 +16,9 @@ package com.android.settings.connecteddevice.audiosharing.audiostreams; +import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; +import static android.content.res.Configuration.ORIENTATION_PORTRAIT; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -32,9 +35,13 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeBroadcastMetadata; import android.bluetooth.BluetoothLeBroadcastReceiveState; import android.content.Context; +import android.content.res.Configuration; +import android.content.res.Resources; +import androidx.fragment.app.FragmentActivity; import androidx.test.core.app.ApplicationProvider; +import com.android.settings.R; import com.android.settings.testutils.shadow.ShadowThreadUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; @@ -42,6 +49,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; +import com.google.android.material.appbar.AppBarLayout; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -91,8 +99,7 @@ public class AudioStreamsHelperTest { @Test public void addSource_noDevice_doNothing() { - when(mAssistant.getAllConnectedDevices()) - .thenReturn(Collections.emptyList()); + when(mAssistant.getAllConnectedDevices()).thenReturn(Collections.emptyList()); mHelper.addSource(mMetadata); verify(mAssistant, never()).addSource(any(), any(), anyBoolean()); @@ -114,8 +121,7 @@ public class AudioStreamsHelperTest { @Test public void removeSource_noDevice_doNothing() { - when(mAssistant.getAllConnectedDevices()) - .thenReturn(Collections.emptyList()); + when(mAssistant.getAllConnectedDevices()).thenReturn(Collections.emptyList()); mHelper.removeSource(BROADCAST_ID_1); verify(mAssistant, never()).removeSource(any(), anyInt()); @@ -236,4 +242,40 @@ public class AudioStreamsHelperTest { verify(mContext).startService(any()); } + + @Test + public void configureAppBarByOrientation_landscape_shouldNotExpand() { + FragmentActivity fragmentActivity = mock(FragmentActivity.class); + // AppBarLayout requires a Theme.AppCompat. + mContext.setTheme(R.style.Theme_Settings_Home); + AppBarLayout appBarLayout = spy(new AppBarLayout(mContext)); + setUpFragment(fragmentActivity, appBarLayout, ORIENTATION_LANDSCAPE); + + AudioStreamsHelper.configureAppBarByOrientation(fragmentActivity); + + verify(appBarLayout).setExpanded(eq(false)); + } + + @Test + public void configureAppBarByOrientation_portrait_shouldExpand() { + FragmentActivity fragmentActivity = mock(FragmentActivity.class); + // AppBarLayout requires a Theme.AppCompat. + mContext.setTheme(R.style.Theme_Settings_Home); + AppBarLayout appBarLayout = spy(new AppBarLayout(mContext)); + setUpFragment(fragmentActivity, appBarLayout, ORIENTATION_PORTRAIT); + + AudioStreamsHelper.configureAppBarByOrientation(fragmentActivity); + + verify(appBarLayout).setExpanded(eq(true)); + } + + private void setUpFragment( + FragmentActivity fragmentActivity, AppBarLayout appBarLayout, int orientationPortrait) { + Resources resources = mock(Resources.class); + when(fragmentActivity.getResources()).thenReturn(resources); + Configuration configuration = new Configuration(); + configuration.orientation = orientationPortrait; + when(resources.getConfiguration()).thenReturn(configuration); + when(fragmentActivity.findViewById(anyInt())).thenReturn(appBarLayout); + } }