1 package com.example.imsmediatestingapp; 2 3 import android.annotation.SuppressLint; 4 import android.content.Context; 5 import android.telephony.imsmedia.EvsParams; 6 import android.view.View; 7 import android.widget.AutoCompleteTextView; 8 import android.widget.PopupMenu; 9 import androidx.annotation.NonNull; 10 import com.google.android.material.bottomsheet.BottomSheetDialog; 11 import com.google.android.material.textfield.TextInputLayout; 12 import java.util.EventListener; 13 import java.util.Objects; 14 15 /** 16 * The BottomSheetAudioCodecSettings class extends the BottomSheetDialog class. It is used when 17 * changing the audio codec during an open IMS audio session. 18 */ 19 public class BottomSheetAudioCodecSettings extends BottomSheetDialog implements EventListener { 20 21 private boolean isOpen = false; 22 AutoCompleteTextView audioCodecDropDown; 23 AutoCompleteTextView evsBandDropdown; 24 AutoCompleteTextView audioCodecModeDropdown; 25 TextInputLayout audioCodecModeDropdownLayout; 26 TextInputLayout evsBandDropdownLayout; 27 private int audioCodec; 28 private int evsMode; 29 private int evsBand; 30 private int amrMode; 31 32 /** 33 * Constructor for the BottomSheetAudioCodecSettings 34 * @param context The context that the BottomSheetDialog will be displayed on top of. 35 */ BottomSheetAudioCodecSettings(@onNull Context context)36 public BottomSheetAudioCodecSettings(@NonNull Context context) { 37 super(context); 38 } 39 40 /** 41 * Sets up the three dropdown lists' onClickListeners 42 */ 43 @Override onStart()44 public void onStart() { 45 super.onStart(); 46 isOpen = true; 47 48 audioCodecDropDown = findViewById(R.id.selectAudioCodecMenu); 49 Objects.requireNonNull(audioCodecDropDown).setOnClickListener( 50 view -> openCodecSelectionMenu()); 51 52 evsBandDropdown = findViewById(R.id.selectEvsBandMenu); 53 Objects.requireNonNull(evsBandDropdown).setOnClickListener( 54 view -> openEvsBandwidthMenu()); 55 56 audioCodecModeDropdown = findViewById(R.id.selectAudioCodecModeMenu); 57 Objects.requireNonNull(audioCodecModeDropdown).setOnClickListener( 58 view -> openAmrModeSelectionMenu()); 59 } 60 61 /** 62 * Changes the isOpen boolean to false after the BottomSheetDialog is dismissed. 63 */ 64 @Override dismiss()65 public void dismiss() { 66 super.dismiss(); 67 isOpen = false; 68 } 69 70 /** 71 * Gets if the BottomSheetDialong is open 72 * @return if the BottomSheetDialog is currently on screen 73 */ isOpen()74 public boolean isOpen() { 75 return isOpen; 76 } 77 78 /** 79 * Displays a PopupMenu filled with the audio codecs from the "audio_codecs_menu.xml" and 80 * configures the onClickListener to save the user's selection. Also contains the logic to 81 * determine which menu should be shown for each selection. 82 */ 83 @SuppressLint("NonConstantResourceId") openCodecSelectionMenu()84 public void openCodecSelectionMenu() { 85 PopupMenu audioCodecMenu = new PopupMenu(getContext(), 86 findViewById(R.id.selectAudioCodecMenu)); 87 audioCodecMenu.getMenuInflater() 88 .inflate(R.menu.audio_codecs_menu, audioCodecMenu.getMenu()); 89 audioCodecMenu.setOnMenuItemClickListener(item -> { 90 audioCodecDropDown.setText(item.getTitle()); 91 audioCodec = Integer.parseInt(String.valueOf(item.getTitleCondensed())); 92 audioCodecModeDropdownLayout = findViewById(R.id.selectAudioCodecModeLayout); 93 evsBandDropdownLayout = findViewById(R.id.selectEvsBandLayout); 94 95 switch (item.getItemId()) { 96 97 case R.id.amrCodecMenuItem: 98 case R.id.amrWbCodecMenuItem: 99 Objects.requireNonNull(audioCodecModeDropdown).setOnClickListener( 100 view -> openAmrModeSelectionMenu()); 101 evsBandDropdownLayout.setVisibility(View.GONE); 102 audioCodecModeDropdownLayout.setVisibility(View.VISIBLE); 103 break; 104 105 case R.id.evsCodecMenuItem: 106 evsBandDropdownLayout.setVisibility(View.VISIBLE); 107 audioCodecModeDropdownLayout.setVisibility(View.GONE); 108 break; 109 110 case R.id.pcmaCodecMenuItem: 111 case R.id.pcmuCodecMenuItem: 112 evsBandDropdownLayout.setVisibility(View.GONE); 113 audioCodecModeDropdownLayout.setVisibility(View.GONE); 114 break; 115 116 default: 117 return false; 118 } 119 120 return true; 121 }); 122 audioCodecMenu.show(); 123 } 124 125 /** 126 * Displays a PopupMenu filled with the EVS bandwidths from the "evs_band_menu.xml". 127 * Also, configures the menu's onClickListener to save the user's selection. 128 */ 129 @SuppressLint("NonConstantResourceId") openEvsBandwidthMenu()130 public void openEvsBandwidthMenu() { 131 PopupMenu evsBandMenu = new PopupMenu(getContext(), findViewById(R.id.selectEvsBandMenu)); 132 evsBandMenu.getMenuInflater().inflate(R.menu.evs_band_menu, evsBandMenu.getMenu()); 133 evsBandMenu.setOnMenuItemClickListener(item -> { 134 evsBandDropdown.setText(item.getTitle()); 135 Objects.requireNonNull(audioCodecModeDropdown).setOnClickListener( 136 view -> openEvsModeSelectionMenu()); 137 audioCodecModeDropdownLayout.setVisibility(View.VISIBLE); 138 evsBand = Integer.parseInt(String.valueOf(item.getTitleCondensed())); 139 switch (item.getItemId()) { 140 case R.id.evsBandNoneMenuItem: 141 evsBand = EvsParams.EVS_BAND_NONE; 142 break; 143 144 case R.id.evsBandNarrowMenuItem: 145 evsBand = EvsParams.EVS_NARROW_BAND; 146 break; 147 148 case R.id.evsBandWideMenuItem: 149 evsBand = EvsParams.EVS_WIDE_BAND; 150 break; 151 152 case R.id.evsBandSuperWideMenuItem: 153 evsBand = EvsParams.EVS_SUPER_WIDE_BAND; 154 break; 155 156 case R.id.evsBandFullMenuItem: 157 evsBand = EvsParams.EVS_FULL_BAND; 158 break; 159 } 160 161 return true; 162 }); 163 evsBandMenu.show(); 164 } 165 166 /** 167 * Displays a PopupMenu filled with the AMR modes from the "amr_modes_menu.xml" and configures 168 * the menu's onClickListener to save the user's selection. 169 */ openAmrModeSelectionMenu()170 public void openAmrModeSelectionMenu() { 171 PopupMenu amrModeMenu = new PopupMenu(getContext(), 172 findViewById(R.id.selectAudioCodecModeMenu)); 173 amrModeMenu.getMenuInflater().inflate(R.menu.amr_modes_menu, amrModeMenu.getMenu()); 174 amrModeMenu.setOnMenuItemClickListener(item -> { 175 audioCodecModeDropdown.setText(item.getTitle()); 176 amrMode = Integer.parseInt(String.valueOf(item.getTitleCondensed())); 177 178 return true; 179 }); 180 amrModeMenu.show(); 181 } 182 183 /** 184 * Displays a PopupMenu filled with the EVS modes from the "evs_modes_menu.xml" and configures 185 * the menu's onClickListener to save the user's selection. 186 */ openEvsModeSelectionMenu()187 public void openEvsModeSelectionMenu() { 188 PopupMenu evsModeMenu = new PopupMenu(getContext(), 189 findViewById(R.id.selectAudioCodecModeMenu)); 190 evsModeMenu.getMenuInflater().inflate(R.menu.evs_modes_menu, evsModeMenu.getMenu()); 191 evsModeMenu.setOnMenuItemClickListener(item -> { 192 audioCodecModeDropdown.setText(item.getTitle()); 193 evsMode = Integer.parseInt(String.valueOf(item.getTitleCondensed())); 194 195 return true; 196 }); 197 evsModeMenu.show(); 198 } 199 200 /** 201 * @return Integer value of the selected EVS mode. 202 */ getEvsMode()203 public int getEvsMode() { 204 return evsMode; 205 } 206 207 /** 208 * @return Integer value of the selected EVS band. 209 */ getEvsBand()210 public int getEvsBand() { 211 return evsBand; 212 } 213 214 /** 215 * @return Integer value of the selected AMR mode. 216 */ getAmrMode()217 public int getAmrMode() { 218 return amrMode; 219 } 220 221 /** 222 * @return Integer value of the selected audio codec type. 223 */ getAudioCodec()224 public int getAudioCodec() { 225 return audioCodec; 226 } 227 } 228