1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settingslib.bluetooth; 18 19 import static com.android.settingslib.bluetooth.HearingAidInfo.DeviceSide.SIDE_LEFT; 20 import static com.android.settingslib.bluetooth.HearingAidInfo.DeviceSide.SIDE_RIGHT; 21 22 import android.bluetooth.BluetoothDevice; 23 24 import androidx.annotation.NonNull; 25 import androidx.annotation.Nullable; 26 27 import java.util.List; 28 import java.util.Map; 29 30 /** Interface for the ambient volume UI. */ 31 public interface AmbientVolumeUi { 32 33 /** Interface definition for a callback to be invoked when event happens in AmbientVolumeUi. */ 34 interface AmbientVolumeUiListener { 35 /** Called when the expand icon is clicked. */ onExpandIconClick()36 void onExpandIconClick(); 37 38 /** Called when the ambient volume icon is clicked. */ onAmbientVolumeIconClick()39 void onAmbientVolumeIconClick(); 40 41 /** Called when the slider of the specified side is changed. */ onSliderValueChange(int side, int value)42 void onSliderValueChange(int side, int value); 43 }; 44 45 /** The rotation degree of the expand icon when the UI is in collapsed mode. */ 46 float ROTATION_COLLAPSED = 0f; 47 /** The rotation degree of the expand icon when the UI is in expanded mode. */ 48 float ROTATION_EXPANDED = 180f; 49 50 /** 51 * The default ambient volume level for hearing device ambient volume icon 52 * 53 * <p> This icon visually represents the current ambient volume. It displays separate 54 * levels for the left and right sides, each with 5 levels ranging from 0 to 4. 55 * 56 * <p> To represent the combined left/right levels with a single value, the following 57 * calculation is used: 58 * finalLevel = (leftLevel * 5) + rightLevel 59 * For example: 60 * <ul> 61 * <li>If left level is 2 and right level is 3, the final level will be 13 (2 * 5 + 3)</li> 62 * <li>If both left and right levels are 0, the final level will be 0</li> 63 * <li>If both left and right levels are 4, the final level will be 24</li> 64 * </ul> 65 */ 66 int AMBIENT_VOLUME_LEVEL_DEFAULT = 24; 67 /** 68 * The minimum ambient volume level for hearing device ambient volume icon 69 * 70 * @see #AMBIENT_VOLUME_LEVEL_DEFAULT 71 */ 72 int AMBIENT_VOLUME_LEVEL_MIN = 0; 73 /** 74 * The maximum ambient volume level for hearing device ambient volume icon 75 * 76 * @see #AMBIENT_VOLUME_LEVEL_DEFAULT 77 */ 78 int AMBIENT_VOLUME_LEVEL_MAX = 24; 79 80 /** 81 * Ths side identifier for slider in collapsed mode which can unified control the ambient 82 * volume of all devices in the same set. 83 */ 84 int SIDE_UNIFIED = 999; 85 86 /** All valid side of the sliders in the UI. */ 87 List<Integer> VALID_SIDES = List.of(SIDE_UNIFIED, SIDE_LEFT, SIDE_RIGHT); 88 89 /** Sets if the UI is visible. */ setVisible(boolean visible)90 void setVisible(boolean visible); 91 92 /** 93 * Sets if the UI is expandable between expanded and collapsed mode. 94 * 95 * <p> If the UI is not expandable, it implies the UI will always stay in collapsed mode 96 */ setExpandable(boolean expandable)97 void setExpandable(boolean expandable); 98 99 /** @return if the UI is expandable. */ isExpandable()100 boolean isExpandable(); 101 102 /** Sets if the UI is in expanded mode. */ setExpanded(boolean expanded)103 void setExpanded(boolean expanded); 104 105 /** @return if the UI is in expanded mode. */ isExpanded()106 boolean isExpanded(); 107 108 /** 109 * Sets if the UI is capable to mute the ambient of the remote device. 110 * 111 * <p> If the value is {@code false}, it implies the remote device ambient will always be 112 * unmute and can not be mute from the UI 113 */ setMutable(boolean mutable)114 void setMutable(boolean mutable); 115 116 /** @return if the UI is capable to mute the ambient of remote device. */ isMutable()117 boolean isMutable(); 118 119 /** Sets if the UI shows mute state. */ setMuted(boolean muted)120 void setMuted(boolean muted); 121 122 /** @return if the UI shows mute state */ isMuted()123 boolean isMuted(); 124 125 /** 126 * Sets listener on the UI. 127 * 128 * @see AmbientVolumeUiListener 129 */ setListener(@ullable AmbientVolumeUiListener listener)130 void setListener(@Nullable AmbientVolumeUiListener listener); 131 132 /** 133 * Sets up sliders in the UI. 134 * 135 * <p> For each side of device, the UI should hava a corresponding slider to control it's 136 * ambient volume. 137 * <p> For all devices in the same set, the UI should have a slider to control all devices' 138 * ambient volume at once. 139 * @param sideToDeviceMap the side and device mapping of all devices in the same set 140 */ setupSliders(@onNull Map<Integer, BluetoothDevice> sideToDeviceMap)141 void setupSliders(@NonNull Map<Integer, BluetoothDevice> sideToDeviceMap); 142 143 /** 144 * Sets if the slider is enabled. 145 * 146 * @param side the side of the slider 147 * @param enabled the enabled state 148 */ setSliderEnabled(int side, boolean enabled)149 void setSliderEnabled(int side, boolean enabled); 150 151 /** 152 * Sets the slider value. 153 * 154 * @param side the side of the slider 155 * @param value the ambient value 156 */ setSliderValue(int side, int value)157 void setSliderValue(int side, int value); 158 159 /** 160 * Sets the slider's minimum and maximum value. 161 * 162 * @param side the side of the slider 163 * @param min the minimum ambient value 164 * @param max the maximum ambient value 165 */ setSliderRange(int side, int min, int max)166 void setSliderRange(int side, int min, int max); 167 168 /** Updates the UI according to current state. */ updateLayout()169 void updateLayout(); 170 } 171