in app/src/main/java/com/amazonaws/services/chime/sdkdemo/fragment/DeviceManagementFragment.kt [104:205]
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_device_management, container, false)
val context = activity as Context
val meetingId = arguments?.getString(HomeActivity.MEETING_ID_KEY)
val name = arguments?.getString(HomeActivity.NAME_KEY)
val audioMode = arguments?.getInt(HomeActivity.AUDIO_MODE_KEY)?.let { intValue ->
AudioMode.from(intValue, defaultAudioMode = AudioMode.Stereo48K)
} ?: AudioMode.Stereo48K
audioVideo = (activity as MeetingActivity).getAudioVideo()
val displayedText = getString(R.string.preview_meeting_info, meetingId, name)
view.findViewById<TextView>(R.id.textViewMeetingPreview)?.text = displayedText
view.findViewById<Button>(R.id.buttonJoin)?.setOnClickListener {
listener.onJoinMeetingClicked()
}
// Note we call isSelected and setSelection before setting onItemSelectedListener
// so that we can control the first time the spinner is set and use previous values
// if they exist (i.e. before rotation). We will set them after lists are populated.
audioDeviceSpinner = view.findViewById(R.id.spinnerAudioDevice)
audioDeviceArrayAdapter = ArrayAdapter(context, android.R.layout.simple_spinner_item, audioDevices)
audioDeviceSpinner.adapter = audioDeviceArrayAdapter
audioDeviceSpinner.isSelected = false
audioDeviceSpinner.setSelection(0, true)
audioDeviceSpinner.onItemSelectedListener = onAudioDeviceSelected
videoDeviceSpinner = view.findViewById(R.id.spinnerVideoDevice)
videoDeviceArrayAdapter = ArrayAdapter(context, android.R.layout.simple_spinner_item, videoDevices)
videoDeviceSpinner.adapter = videoDeviceArrayAdapter
videoDeviceSpinner.isSelected = false
videoDeviceSpinner.setSelection(0, true)
videoDeviceSpinner.onItemSelectedListener = onVideoDeviceSelected
videoFormatSpinner = view.findViewById(R.id.spinnerVideoFormat)
videoFormatArrayAdapter =
ArrayAdapter(context, android.R.layout.simple_spinner_item, videoFormats)
videoFormatSpinner.adapter = videoFormatArrayAdapter
videoFormatSpinner.isSelected = false
videoFormatSpinner.setSelection(0, true)
videoFormatSpinner.onItemSelectedListener = onVideoFormatSelected
audioVideo.addDeviceChangeObserver(this)
cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
cameraCaptureSource = (activity as MeetingActivity).getCameraCaptureSource()
view.findViewById<DefaultVideoRenderView>(R.id.videoPreview)?.let {
val displayMetrics = context.resources.displayMetrics
val width =
if (isLandscapeMode(context)) displayMetrics.widthPixels / 2 else displayMetrics.widthPixels
val height = (width * VIDEO_ASPECT_RATIO_16_9).toInt()
it.layoutParams.width = width
it.layoutParams.height = height
it.logger = logger
it.init((activity as MeetingActivity).getEglCoreFactory())
cameraCaptureSource.addVideoSink(it)
videoPreview = it
}
uiScope.launch {
populateDeviceList(audioVideo.listAudioDevices(), audioDevices, audioDeviceArrayAdapter)
populateDeviceList(MediaDevice.listVideoDevices(cameraManager), videoDevices, videoDeviceArrayAdapter)
cameraCaptureSource.device ?.let {
populateVideoFormatList(MediaDevice.listSupportedVideoCaptureFormats(cameraManager, it, MAX_VIDEO_FORMAT_FPS, MAX_VIDEO_FORMAT_WIDTH, MAX_VIDEO_FORMAT_HEIGHT))
}
videoPreview.mirror =
cameraCaptureSource.device?.type == MediaDeviceType.VIDEO_FRONT_CAMERA
var audioDeviceSpinnerIndex = 0
var videoDeviceSpinnerIndex = 0
var videoFormatSpinnerIndex = 0
if (savedInstanceState != null) {
audioDeviceSpinnerIndex = savedInstanceState.getInt(AUDIO_DEVICE_SPINNER_INDEX_KEY, 0)
videoDeviceSpinnerIndex = savedInstanceState.getInt(VIDEO_DEVICE_SPINNER_INDEX_KEY, 0)
videoFormatSpinnerIndex = savedInstanceState.getInt(VIDEO_FORMAT_SPINNER_INDEX_KEY, 0)
}
audioDeviceSpinner.setSelection(audioDeviceSpinnerIndex)
videoDeviceSpinner.setSelection(videoDeviceSpinnerIndex)
videoFormatSpinner.setSelection(videoFormatSpinnerIndex)
// Setting the selection won't immediately callback, so we need to explicitly set the values
// of the camera capturer before starting it
cameraCaptureSource.device = videoDeviceSpinner.getItemAtPosition(videoDeviceSpinnerIndex) as MediaDevice
videoPreview.mirror = cameraCaptureSource.device?.type == MediaDeviceType.VIDEO_FRONT_CAMERA
cameraCaptureSource.format = videoFormatSpinner.getItemAtPosition(videoFormatSpinnerIndex) as VideoCaptureFormat
cameraCaptureSource.start()
}
return view
}