diff options
| author | 2024-12-30 11:51:21 -0800 | |
|---|---|---|
| committer | 2024-12-30 11:51:21 -0800 | |
| commit | 1ed830bf64e0e966aa2ca37e919f08799a12e4a4 (patch) | |
| tree | 315fab7ab8105671afed57cb26a2f59b789fc9ef | |
| parent | 9330fc991c646110d2c47e38974a9704bcb60826 (diff) | |
| parent | 1da494c558c44fb0e164f393d0ca7fe9af788b54 (diff) | |
Merge "[HA Status] Show the connection status drawable for hearing device in floating menu" into main
12 files changed, 331 insertions, 10 deletions
diff --git a/core/res/res/drawable/ic_accessibility_hearing_aid.xml b/core/res/res/drawable/ic_accessibility_hearing_aid.xml index e5ffeb0274fc..79c61a64302d 100644 --- a/core/res/res/drawable/ic_accessibility_hearing_aid.xml +++ b/core/res/res/drawable/ic_accessibility_hearing_aid.xml @@ -17,8 +17,10 @@ <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <background android:drawable="@color/accessibility_feature_background" /> <foreground> + <!-- TODO: b/382377298 - To update correct drawable with same inset + @dimen/accessibility_icon_foreground_padding_ratio or remove the inset together. --> <inset android:drawable="@drawable/ic_accessibility_hearing_aid_foreground" - android:inset="@dimen/accessibility_icon_foreground_padding_ratio" /> + android:inset="30%" /> </foreground> </adaptive-icon> diff --git a/core/res/res/drawable/ic_accessibility_hearing_aid_blue_dot.xml b/core/res/res/drawable/ic_accessibility_hearing_aid_blue_dot.xml new file mode 100644 index 000000000000..4f0036ccd8d2 --- /dev/null +++ b/core/res/res/drawable/ic_accessibility_hearing_aid_blue_dot.xml @@ -0,0 +1,27 @@ +<!-- + Copyright (C) 2024 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="14dp" + android:height="14dp" + android:viewportWidth="14" + android:viewportHeight="14"> + <path + android:pathData="M7,7m-6,0a6,6 0,1 1,12 0a6,6 0,1 1,-12 0" + android:strokeWidth="2" + android:fillColor="#3998D3" + android:strokeColor="#3E373C"/> +</vector> diff --git a/core/res/res/drawable/ic_accessibility_hearing_aid_disconnected.xml b/core/res/res/drawable/ic_accessibility_hearing_aid_disconnected.xml new file mode 100644 index 000000000000..2b302e18ad37 --- /dev/null +++ b/core/res/res/drawable/ic_accessibility_hearing_aid_disconnected.xml @@ -0,0 +1,26 @@ +<!-- + Copyright (C) 2024 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. +--> + +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> + <background android:drawable="@color/accessibility_feature_background" /> + <foreground> + <!-- TODO: b/382377298 - To update correct drawable with same inset + @dimen/accessibility_icon_foreground_padding_ratio or remove the inset together. --> + <inset + android:drawable="@drawable/ic_accessibility_hearing_aid_disconnected_foreground" + android:inset="30%" /> + </foreground> +</adaptive-icon> diff --git a/core/res/res/drawable/ic_accessibility_hearing_aid_disconnected_foreground.xml b/core/res/res/drawable/ic_accessibility_hearing_aid_disconnected_foreground.xml new file mode 100644 index 000000000000..1097ed9067d7 --- /dev/null +++ b/core/res/res/drawable/ic_accessibility_hearing_aid_disconnected_foreground.xml @@ -0,0 +1,26 @@ +<!-- + Copyright (C) 2024 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="22dp" + android:height="23dp" + android:viewportWidth="22" + android:viewportHeight="23"> + <path + android:pathData="M13,1C14.275,1 15.42,1.284 16.435,1.851L14.934,3.352C14.346,3.117 13.701,3 13,3C11.583,3 10.396,3.479 9.438,4.438C8.479,5.396 8,6.583 8,8C8,8.671 8.109,9.324 8.326,9.96L6.794,11.492C6.265,10.355 6,9.191 6,8C6,6.033 6.675,4.375 8.025,3.025C9.375,1.675 11.033,1 13,1ZM13,4.5C13.251,4.5 13.491,4.522 13.72,4.566L9.566,8.72C9.522,8.49 9.5,8.25 9.5,8C9.5,7.033 9.842,6.208 10.525,5.525C11.208,4.842 12.033,4.5 13,4.5ZM9.332,14.582L1.707,22.207L0.293,20.793L20.293,0.793L21.707,2.207L19.22,4.694C19.74,5.677 20,6.779 20,8H18C18,7.356 17.901,6.76 17.703,6.211L16.465,7.449C16.514,7.793 16.509,8.152 16.45,8.525L20.575,12.1L19.075,13.3C19.408,13.833 19.646,14.421 19.788,15.063C19.929,15.704 20,16.35 20,17C20,18.1 19.608,19.042 18.825,19.825C18.042,20.608 17.1,21 16,21C15.05,21 14.217,20.717 13.5,20.15C12.783,19.583 12.267,18.833 11.95,17.9C11.667,17.067 11.363,16.45 11.038,16.05C10.712,15.65 10.175,15.183 9.425,14.65C9.394,14.628 9.363,14.605 9.332,14.582ZM10.756,13.158C11.518,13.704 12.129,14.23 12.587,14.738C13.063,15.262 13.442,15.975 13.725,16.875C13.908,17.458 14.188,17.958 14.563,18.375C14.938,18.792 15.417,19 16,19C16.533,19 17,18.804 17.4,18.413C17.8,18.021 18,17.55 18,17C18,16.567 17.958,16.138 17.875,15.712C17.792,15.288 17.658,14.9 17.475,14.55L15.775,15.9L13.275,11.5C12.985,11.524 12.706,11.516 12.438,11.477L10.756,13.158ZM3.989,14.297L5.434,12.852C5.145,12.405 4.896,11.934 4.688,11.438C4.229,10.346 4,9.2 4,8C4,6.783 4.229,5.625 4.688,4.525C5.146,3.425 5.8,2.45 6.65,1.6L5.2,0.2C4.167,1.25 3.375,2.446 2.825,3.788C2.275,5.129 2,6.533 2,8C2,9.433 2.275,10.821 2.825,12.163C3.136,12.921 3.524,13.632 3.989,14.297ZM16.375,12.9L17.425,12.05L15.55,10.4L15.363,10.587C15.304,10.646 15.242,10.7 15.175,10.75L16.375,12.9Z" + android:fillColor="#ffffff" + android:fillType="evenOdd"/> +</vector> diff --git a/core/res/res/drawable/ic_accessibility_hearing_aid_green_dot.xml b/core/res/res/drawable/ic_accessibility_hearing_aid_green_dot.xml new file mode 100644 index 000000000000..e8f0063bb4a8 --- /dev/null +++ b/core/res/res/drawable/ic_accessibility_hearing_aid_green_dot.xml @@ -0,0 +1,27 @@ +<!-- + Copyright (C) 2024 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="14dp" + android:height="14dp" + android:viewportWidth="14" + android:viewportHeight="14"> + <path + android:pathData="M7,7m-6,0a6,6 0,1 1,12 0a6,6 0,1 1,-12 0" + android:strokeWidth="2" + android:fillColor="#6DD58C" + android:strokeColor="#3E373C"/> +</vector> diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 33d3858562af..6313054e47f5 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -4947,6 +4947,18 @@ <!-- Title of hearing aids feature, shown in the warning dialog about the accessibility shortcut. [CHAR LIMIT=none] --> <string name="hearing_aids_feature_name">Hearing devices</string> + <!-- Text of hearing device disconnected state. [CHAR LIMIT=20] --> + <string name="hearing_device_status_disconnected">Disconnected</string> + + <!-- Text of hearing device connected state. [CHAR LIMIT=20] --> + <string name="hearing_device_status_connected">Connected</string> + + <!-- Text of hearing device active state. Active means device is currently connected and able to streaming the sound. [CHAR LIMIT=20] --> + <string name="hearing_device_status_active">Active</string> + + <!-- Text of hearing device loading state. Loading means device is not available yet, it might be in connecting or disconnecting. [CHAR LIMIT=20] --> + <string name="hearing_device_status_loading">Loading</string> + <!-- Text in toast to alert the user that the accessibility shortcut turned on an accessibility service. [CHAR LIMIT=none] --> <string name="accessibility_shortcut_enabling_service">Held volume keys. <xliff:g id="service_name" example="TalkBack">%1$s</xliff:g> turned on.</string> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 4789624685c2..4d533ec94635 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -3821,10 +3821,18 @@ <java-symbol type="drawable" name="ic_accessibility_color_correction" /> <java-symbol type="drawable" name="ic_accessibility_generic" /> <java-symbol type="drawable" name="ic_accessibility_hearing_aid" /> + <java-symbol type="drawable" name="ic_accessibility_hearing_aid_disconnected" /> + <java-symbol type="drawable" name="ic_accessibility_hearing_aid_green_dot" /> + <java-symbol type="drawable" name="ic_accessibility_hearing_aid_blue_dot" /> <java-symbol type="drawable" name="ic_accessibility_magnification" /> <java-symbol type="drawable" name="ic_accessibility_reduce_bright_colors" /> <java-symbol type="drawable" name="ic_accessibility_one_handed" /> + <java-symbol type="string" name="hearing_device_status_disconnected" /> + <java-symbol type="string" name="hearing_device_status_connected" /> + <java-symbol type="string" name="hearing_device_status_active" /> + <java-symbol type="string" name="hearing_device_status_loading" /> + <java-symbol type="string" name="hearing_aids_feature_name" /> <java-symbol type="string" name="reduce_bright_colors_feature_name" /> <java-symbol type="string" name="one_handed_mode_feature_name" /> diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/floatingmenu/AccessibilityTargetAdapterTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/floatingmenu/AccessibilityTargetAdapterTest.java index b08f97a646b9..a3c5a382c53a 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/floatingmenu/AccessibilityTargetAdapterTest.java +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/floatingmenu/AccessibilityTargetAdapterTest.java @@ -16,11 +16,15 @@ package com.android.systemui.accessibility.floatingmenu; +import static com.android.internal.accessibility.AccessibilityShortcutController.ACCESSIBILITY_HEARING_AIDS_COMPONENT_NAME; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; +import android.content.ComponentName; import android.graphics.drawable.Drawable; +import android.platform.test.annotations.EnableFlags; import android.view.LayoutInflater; import android.view.View; @@ -28,15 +32,18 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import com.android.internal.accessibility.dialog.AccessibilityTarget; +import com.android.settingslib.bluetooth.HearingAidDeviceManager.ConnectionStatus; import com.android.systemui.SysuiTestCase; import com.android.systemui.accessibility.floatingmenu.AccessibilityTargetAdapter.ViewHolder; import com.android.systemui.res.R; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import java.util.ArrayList; import java.util.List; @@ -45,23 +52,24 @@ import java.util.List; @SmallTest @RunWith(AndroidJUnit4.class) public class AccessibilityTargetAdapterTest extends SysuiTestCase { + @Rule + public final MockitoRule mMockitoRule = MockitoJUnit.rule(); + @Mock private AccessibilityTarget mAccessibilityTarget; - @Mock private Drawable mIcon; - @Mock private Drawable.ConstantState mConstantState; + private static final int PAYLOAD_HEARING_STATUS_DRAWABLE = 1; private ViewHolder mViewHolder; private AccessibilityTargetAdapter mAdapter; private final List<AccessibilityTarget> mTargets = new ArrayList<>(); + private static final ComponentName TEST_NAME = new ComponentName("test.pkg", "test.activitty"); @Before public void setUp() { - MockitoAnnotations.initMocks(this); - mTargets.add(mAccessibilityTarget); mAdapter = new AccessibilityTargetAdapter(mTargets); @@ -69,6 +77,7 @@ public class AccessibilityTargetAdapterTest extends SysuiTestCase { R.layout.accessibility_floating_menu_item, null); mViewHolder = new ViewHolder(rootView); when(mAccessibilityTarget.getIcon()).thenReturn(mIcon); + when(mAccessibilityTarget.getId()).thenReturn(TEST_NAME.flattenToString()); when(mIcon.getConstantState()).thenReturn(mConstantState); } @@ -105,4 +114,35 @@ public class AccessibilityTargetAdapterTest extends SysuiTestCase { assertThat(mViewHolder.itemView.getStateDescription().toString().contentEquals( "testState")).isTrue(); } + + @Test + @EnableFlags( + com.android.settingslib.flags.Flags.FLAG_HEARING_DEVICE_SET_CONNECTION_STATUS_REPORT) + public void onHearingDeviceStatusChanged_disconnected_getExpectedStateDescription() { + when(mAccessibilityTarget.getId()).thenReturn( + ACCESSIBILITY_HEARING_AIDS_COMPONENT_NAME.flattenToString()); + int indexInTarget = 0; + + mAdapter.onHearingDeviceStatusChanged(ConnectionStatus.DISCONNECTED, indexInTarget); + mAdapter.onBindViewHolder(mViewHolder, indexInTarget); + + assertThat(mViewHolder.itemView.getStateDescription().toString().contentEquals( + "Disconnected")).isTrue(); + } + + @Test + @EnableFlags( + com.android.settingslib.flags.Flags.FLAG_HEARING_DEVICE_SET_CONNECTION_STATUS_REPORT) + public void onBindViewHolder_withPayloadDisconnected_getExpectedStateDescription() { + when(mAccessibilityTarget.getId()).thenReturn( + ACCESSIBILITY_HEARING_AIDS_COMPONENT_NAME.flattenToString()); + int indexInTarget = 0; + + mAdapter.onHearingDeviceStatusChanged(ConnectionStatus.DISCONNECTED, indexInTarget); + mAdapter.onBindViewHolder(mViewHolder, indexInTarget, + List.of(PAYLOAD_HEARING_STATUS_DRAWABLE)); + + assertThat(mViewHolder.itemView.getStateDescription().toString().contentEquals( + "Disconnected")).isTrue(); + } } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandlerTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandlerTest.java index fbd8a713a249..715c40a31632 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandlerTest.java +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/accessibility/floatingmenu/MenuListViewTouchHandlerTest.java @@ -113,7 +113,8 @@ public class MenuListViewTouchHandlerTest extends SysuiTestCase { mTouchHandler = new MenuListViewTouchHandler(mMenuAnimationController, mDragToInteractAnimationController); - final AccessibilityTargetAdapter stubAdapter = new AccessibilityTargetAdapter(mStubTargets); + final AccessibilityTargetAdapter stubAdapter = new AccessibilityTargetAdapter( + mStubTargets); mStubListView = (RecyclerView) mStubMenuView.getChildAt(0); mStubListView.setAdapter(stubAdapter); } diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityTargetAdapter.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityTargetAdapter.java index 5160309e7c72..fe80f540d5d3 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityTargetAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityTargetAdapter.java @@ -16,6 +16,10 @@ package com.android.systemui.accessibility.floatingmenu; +import static com.android.internal.accessibility.AccessibilityShortcutController.ACCESSIBILITY_HEARING_AIDS_COMPONENT_NAME; + +import android.content.ComponentName; +import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -29,7 +33,10 @@ import androidx.recyclerview.widget.RecyclerView.Adapter; import com.android.internal.accessibility.common.ShortcutConstants.AccessibilityFragmentType; import com.android.internal.accessibility.dialog.AccessibilityTarget; +import com.android.settingslib.bluetooth.HearingAidDeviceManager; +import com.android.settingslib.bluetooth.HearingAidDeviceManager.ConnectionStatus; import com.android.systemui.accessibility.floatingmenu.AccessibilityTargetAdapter.ViewHolder; +import com.android.systemui.accessibility.hearingaid.HearingDeviceStatusDrawableInfo; import com.android.systemui.res.R; import java.lang.annotation.Retention; @@ -40,10 +47,14 @@ import java.util.List; * An adapter which shows the set of accessibility targets that can be performed. */ public class AccessibilityTargetAdapter extends Adapter<ViewHolder> { + private static final int PAYLOAD_HEARING_STATUS_DRAWABLE = 1; + private int mIconWidthHeight; private int mItemPadding; private final List<AccessibilityTarget> mTargets; + private int mHearingDeviceStatus; + @IntDef({ ItemType.FIRST_ITEM, ItemType.REGULAR_ITEM, @@ -56,7 +67,7 @@ public class AccessibilityTargetAdapter extends Adapter<ViewHolder> { int LAST_ITEM = 2; } - public AccessibilityTargetAdapter(List<AccessibilityTarget> targets) { + public AccessibilityTargetAdapter(@NonNull List<AccessibilityTarget> targets) { mTargets = targets; } @@ -95,6 +106,32 @@ public class AccessibilityTargetAdapter extends Adapter<ViewHolder> { ViewCompat.replaceAccessibilityAction(holder.itemView, AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_CLICK, clickHint, /* command= */ null); + + if (com.android.settingslib.flags.Flags.hearingDeviceSetConnectionStatusReport()) { + if (ACCESSIBILITY_HEARING_AIDS_COMPONENT_NAME.equals( + ComponentName.unflattenFromString(target.getId()))) { + updateHearingDeviceStatusDrawable(holder, mHearingDeviceStatus); + } + } + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position, + @NonNull List<Object> payloads) { + if (payloads.isEmpty()) { + onBindViewHolder(holder, position); + return; + } + + if (com.android.settingslib.flags.Flags.hearingDeviceSetConnectionStatusReport()) { + payloads.forEach(payload -> { + if (payload instanceof Integer cmd) { + if (cmd == PAYLOAD_HEARING_STATUS_DRAWABLE) { + updateHearingDeviceStatusDrawable(holder, mHearingDeviceStatus); + } + } + }); + } } @ItemType @@ -126,6 +163,37 @@ public class AccessibilityTargetAdapter extends Adapter<ViewHolder> { mItemPadding = itemPadding; } + /** + * Notifies to update the hearing device status drawable at the given target index. + * + * @param status the connection status for hearing devices. + * {@link HearingAidDeviceManager.ConnectionStatus} + * @param targetIndex The index of the hearing aid device in the target list, or -1 if not + * exist. + */ + public void onHearingDeviceStatusChanged(@HearingAidDeviceManager.ConnectionStatus int status, + int targetIndex) { + mHearingDeviceStatus = status; + + if (targetIndex >= 0) { + notifyItemChanged(targetIndex, PAYLOAD_HEARING_STATUS_DRAWABLE); + } + } + + private void updateHearingDeviceStatusDrawable(ViewHolder holder, + @ConnectionStatus int status) { + final Context context = holder.itemView.getContext(); + HearingDeviceStatusDrawableInfo.StatusDrawableInfo statusDrawableInfo = + HearingDeviceStatusDrawableInfo.get(status); + final int baseDrawableId = statusDrawableInfo.baseDrawableId(); + final int stateDescriptionId = statusDrawableInfo.stateDescriptionId(); + + holder.mIconView.setBackground( + (baseDrawableId != 0) ? context.getDrawable(baseDrawableId) : null); + holder.itemView.setStateDescription( + (stateDescriptionId != 0) ? context.getString(stateDescriptionId) : null); + } + static class ViewHolder extends RecyclerView.ViewHolder { final View mIconView; diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuView.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuView.java index 23fc546dd9b3..4b6ab6f508ad 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuView.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuView.java @@ -90,6 +90,7 @@ class MenuView extends FrameLayout implements mTargetFeaturesView = new RecyclerView(context); mTargetFeaturesView.setAdapter(mAdapter); mTargetFeaturesView.setLayoutManager(new LinearLayoutManager(context)); + mTargetFeaturesView.setClipChildren(false); setLayoutParams(new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); // Avoid drawing out of bounds of the parent view setClipToOutline(true); @@ -434,11 +435,21 @@ class MenuView extends FrameLayout implements } private void updateHearingDeviceStatus(@HearingAidDeviceManager.ConnectionStatus int status) { - // TODO: b/357882387 - To update status drawable according to the status here. + final int haStatus = mMenuViewModel.getHearingDeviceStatusData().getValue(); + final int haPosition = mMenuViewModel.getHearingDeviceTargetIndexData().getValue(); + if (haPosition >= 0) { + mContext.getMainExecutor().execute( + () -> mAdapter.onHearingDeviceStatusChanged(haStatus, haPosition)); + } } private void updateHearingDeviceTargetIndex(int position) { - // TODO: b/357882387 - To update status drawable according to the status here. + final int haStatus = mMenuViewModel.getHearingDeviceStatusData().getValue(); + final int haPosition = mMenuViewModel.getHearingDeviceTargetIndexData().getValue(); + if (haPosition >= 0) { + mContext.getMainExecutor().execute( + () -> mAdapter.onHearingDeviceStatusChanged(haStatus, haPosition)); + } } /** diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/hearingaid/HearingDeviceStatusDrawableInfo.java b/packages/SystemUI/src/com/android/systemui/accessibility/hearingaid/HearingDeviceStatusDrawableInfo.java new file mode 100644 index 000000000000..ff9bfec7f5bd --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/accessibility/hearingaid/HearingDeviceStatusDrawableInfo.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2024 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.systemui.accessibility.hearingaid; + +import com.android.settingslib.bluetooth.HearingAidDeviceManager.ConnectionStatus; + +/** + * A utility class to get the hearing device status drawable and its description for the + * given connection status. Hearing device status drawable combine with base and indicator + * drawable. + */ +public final class HearingDeviceStatusDrawableInfo { + + private static final StatusDrawableInfo DRAWABLE_DEFAULT_INFO = new StatusDrawableInfo( + com.android.internal.R.drawable.ic_accessibility_hearing_aid, + 0, + 0); + private static final StatusDrawableInfo DRAWABLE_DISCONNECTED_INFO = new StatusDrawableInfo( + com.android.internal.R.drawable.ic_accessibility_hearing_aid_disconnected, + 0, + com.android.internal.R.string.hearing_device_status_disconnected); + private static final StatusDrawableInfo DRAWABLE_CONNECTED_INFO = new StatusDrawableInfo( + com.android.internal.R.drawable.ic_accessibility_hearing_aid, + com.android.internal.R.drawable.ic_accessibility_hearing_aid_blue_dot, + com.android.internal.R.string.hearing_device_status_connected); + private static final StatusDrawableInfo DRAWABLE_ACTIVE_INFO = new StatusDrawableInfo( + com.android.internal.R.drawable.ic_accessibility_hearing_aid, + com.android.internal.R.drawable.ic_accessibility_hearing_aid_green_dot, + com.android.internal.R.string.hearing_device_status_active); + + private HearingDeviceStatusDrawableInfo() {} + + /** + * Returns the corresponding {@link StatusDrawableInfo} for the given {@link ConnectionStatus}. + */ + public static StatusDrawableInfo get(@ConnectionStatus int status) { + return switch (status) { + case ConnectionStatus.DISCONNECTED -> DRAWABLE_DISCONNECTED_INFO; + case ConnectionStatus.CONNECTED -> DRAWABLE_CONNECTED_INFO; + case ConnectionStatus.ACTIVE -> DRAWABLE_ACTIVE_INFO; + // TODO: b/357882387 - Handle to show connecting or disconnecting status drawable + case ConnectionStatus.CONNECTING_OR_DISCONNECTING, ConnectionStatus.NO_DEVICE_BONDED -> + DRAWABLE_DEFAULT_INFO; + default -> DRAWABLE_DEFAULT_INFO; + }; + } + + /** + * A data class that holds the base drawable, indicator drawable and state description to + * represent hearing device connection status. + * + * @param baseDrawableId the base drawable id for the hearing device status + * @param indicatorDrawableId the indicator drawable id for the hearing device status + * @param stateDescriptionId the description for the hearing device status + */ + public record StatusDrawableInfo(int baseDrawableId, int indicatorDrawableId, + int stateDescriptionId) { + } +} |