Add background to ambient volume control icons

Enhance the visibility and discoverability of ambient volume control
icons by adding backgrounds.

Flag: EXEMPT bugfix
Bug: 398962101
Test: manual check the result and screenshots attached on bug
Change-Id: Ice467191235df63f258bbca4e085fbf8a7f3c555
This commit is contained in:
Angela Wang
2025-03-06 12:54:53 +00:00
parent cf0d8cba31
commit c47713d66f
8 changed files with 185 additions and 15 deletions

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2025 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.
-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ambient_icon_background"
android:insetTop="10dp"
android:insetBottom="10dp"/>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2025 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.
-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ambient_icon_background_expressive"
android:insetTop="10dp"
android:insetBottom="10dp"/>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2025 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.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:shape="rectangle">
<solid android:color="@androidprv:color/materialColorSurfaceContainerHigh" />
<corners
android:bottomLeftRadius="?android:attr/dialogCornerRadius"
android:topLeftRadius="?android:attr/dialogCornerRadius"
android:bottomRightRadius="?android:attr/dialogCornerRadius"
android:topRightRadius="?android:attr/dialogCornerRadius"/>
</shape>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2025 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.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:shape="rectangle">
<solid android:color="@androidprv:color/materialColorSurfaceContainer" />
<corners
android:bottomLeftRadius="?android:attr/dialogCornerRadius"
android:topLeftRadius="?android:attr/dialogCornerRadius"
android:bottomRightRadius="?android:attr/dialogCornerRadius"
android:topRightRadius="?android:attr/dialogCornerRadius"/>
</shape>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2025 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:androidprv="http://schemas.android.com/apk/prv/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:clipToPadding="false">
<include layout="@layout/settingslib_expressive_preference_icon_frame"/>
<include layout="@layout/settingslib_expressive_preference_text_frame" />
<ImageView
android:id="@+id/expand_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:contentDescription="@null"
android:tint="@androidprv:color/materialColorOnPrimaryContainer"
android:src="@drawable/ic_keyboard_arrow_down"
android:background="@drawable/ambient_expand_icon_background_expressive" />
</LinearLayout>

View File

@@ -17,6 +17,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
@@ -26,10 +27,21 @@
android:clickable="false"
android:orientation="horizontal">
<include
layout="@layout/settingslib_icon_frame"
<LinearLayout
android:id="@+id/icon_frame"
android:layout_width="48dp"
android:layout_height="48dp"/>
android:layout_height="48dp"
android:gravity="center"
android:layout_marginEnd="@dimen/settingslib_expressive_space_extrasmall6"
android:filterTouchesWhenObscured="false">
<androidx.preference.internal.PreferenceImageView
android:id="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:maxWidth="48dp"
app:maxHeight="48dp" />
</LinearLayout>
<TextView
android:id="@android:id/title"
@@ -48,6 +60,7 @@
android:padding="10dp"
android:contentDescription="@null"
android:tint="@androidprv:color/materialColorOnPrimaryContainer"
android:src="@drawable/ic_keyboard_arrow_down"/>
android:src="@drawable/ic_keyboard_arrow_down"
android:background="@drawable/ambient_expand_icon_background"/>
</LinearLayout>

View File

@@ -39,6 +39,7 @@ import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.bluetooth.AmbientVolumeUi;
import com.android.settingslib.widget.SettingsThemeHelper;
import com.android.settingslib.widget.SliderPreference;
import com.google.common.collect.BiMap;
@@ -68,6 +69,8 @@ public class AmbientVolumePreference extends PreferenceGroup implements AmbientV
@Nullable
private View mExpandIcon;
@Nullable
private View mVolumeIconFrame;
@Nullable
private ImageView mVolumeIcon;
private boolean mExpandable = true;
private boolean mExpanded = false;
@@ -95,7 +98,10 @@ public class AmbientVolumePreference extends PreferenceGroup implements AmbientV
public AmbientVolumePreference(@NonNull Context context) {
super(context, null);
setLayoutResource(R.layout.preference_ambient_volume);
int resId = SettingsThemeHelper.isExpressiveTheme(context)
? R.layout.preference_ambient_volume_expressive
: R.layout.preference_ambient_volume;
setLayoutResource(resId);
setIcon(com.android.settingslib.R.drawable.ic_ambient_volume);
setTitle(R.string.bluetooth_ambient_volume_control);
setSelectable(false);
@@ -110,8 +116,12 @@ public class AmbientVolumePreference extends PreferenceGroup implements AmbientV
mVolumeIcon = holder.itemView.requireViewById(com.android.internal.R.id.icon);
mVolumeIcon.getDrawable().mutate().setTint(getContext().getColor(
com.android.internal.R.color.materialColorOnPrimaryContainer));
final View iconView = holder.itemView.requireViewById(R.id.icon_frame);
iconView.setOnClickListener(v -> {
mVolumeIconFrame = holder.itemView.requireViewById(R.id.icon_frame);
int volumeIconBackgroundResId = SettingsThemeHelper.isExpressiveTheme(getContext())
? R.drawable.ambient_icon_background_expressive
: R.drawable.ambient_icon_background;
mVolumeIconFrame.setBackgroundResource(volumeIconBackgroundResId);
mVolumeIconFrame.setOnClickListener(v -> {
if (!mMutable) {
return;
}
@@ -313,7 +323,7 @@ public class AmbientVolumePreference extends PreferenceGroup implements AmbientV
}
private void updateVolumeIcon() {
if (mVolumeIcon == null) {
if (mVolumeIcon == null || mVolumeIconFrame == null) {
return;
}
mVolumeIcon.setImageLevel(mMuted ? 0 : mVolumeLevel);
@@ -321,10 +331,10 @@ public class AmbientVolumePreference extends PreferenceGroup implements AmbientV
final int stringRes = mMuted ? R.string.bluetooth_ambient_volume_unmute
: R.string.bluetooth_ambient_volume_mute;
mVolumeIcon.setContentDescription(getContext().getString(stringRes));
mVolumeIcon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
mVolumeIconFrame.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
} else {
mVolumeIcon.setContentDescription(null);
mVolumeIcon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
mVolumeIconFrame.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
}
}

View File

@@ -20,6 +20,7 @@ import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceContro
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceController.ORDER_AMBIENT_VOLUME;
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -133,11 +134,17 @@ public class BluetoothDetailsAmbientVolumePreferenceController extends Bluetooth
@Override
public boolean isAvailable() {
return mCachedDevice.isHearingDevice()
&& mCachedDevice.getProfiles().stream().anyMatch(
profile -> profile instanceof VolumeControlProfile)
&& mAmbientUiController != null
&& mAmbientUiController.isAmbientControlAvailable();
boolean isHearingDevice = mCachedDevice.isHearingDevice();
boolean supportVcp = mCachedDevice.getProfiles().stream().anyMatch(
profile -> profile instanceof VolumeControlProfile);
boolean hasAmbientControl =
mAmbientUiController != null && mAmbientUiController.isAmbientControlAvailable();
if (DEBUG) {
Log.v(TAG, "isAvailable, isHearingDevice=" + isHearingDevice
+ ", supportVcp=" + supportVcp
+ ", hasAmbientControl=" + hasAmbientControl);
}
return isHearingDevice && supportVcp && hasAmbientControl;
}
@Nullable