1 /* 2 * Copyright (C) 2020 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.systemui.screenrecord; 18 19 import android.content.Context; 20 import android.content.res.Resources; 21 import android.view.LayoutInflater; 22 import android.view.View; 23 import android.view.ViewGroup; 24 import android.widget.ArrayAdapter; 25 import android.widget.LinearLayout; 26 import android.widget.TextView; 27 28 import com.android.systemui.res.R; 29 30 import java.util.List; 31 32 /** 33 * Screen recording view adapter 34 */ 35 public class ScreenRecordingAdapter extends ArrayAdapter<ScreenRecordingAudioSource> { 36 private LinearLayout mSelectedMic; 37 private LinearLayout mSelectedInternal; 38 private LinearLayout mSelectedMicAndInternal; 39 ScreenRecordingAdapter(Context context, int resource, List<ScreenRecordingAudioSource> objects)40 public ScreenRecordingAdapter(Context context, int resource, 41 List<ScreenRecordingAudioSource> objects) { 42 super(context, resource, objects); 43 initViews(); 44 } 45 initViews()46 private void initViews() { 47 mSelectedInternal = getSelected(R.string.screenrecord_device_audio_label); 48 mSelectedMic = getSelected(R.string.screenrecord_mic_label); 49 mSelectedMicAndInternal = getSelected(R.string.screenrecord_device_audio_and_mic_label); 50 } 51 getOption(int label, int description)52 private LinearLayout getOption(int label, int description) { 53 LayoutInflater inflater = LayoutInflater.from(getContext()); 54 LinearLayout layout = (LinearLayout) inflater 55 .inflate(R.layout.screen_record_dialog_audio_source, null, false); 56 ((TextView) layout.findViewById(R.id.screen_recording_dialog_source_text)) 57 .setText(label); 58 TextView descriptionView = layout.findViewById( 59 R.id.screen_recording_dialog_source_description); 60 if (description != Resources.ID_NULL) { 61 descriptionView.setText(description); 62 } else { 63 descriptionView.setVisibility(View.GONE); 64 } 65 return layout; 66 } 67 getSelected(int label)68 private LinearLayout getSelected(int label) { 69 LayoutInflater inflater = LayoutInflater.from(getContext()); 70 LinearLayout layout = (LinearLayout) inflater 71 .inflate(R.layout.screen_record_dialog_audio_source_selected, null, false); 72 ((TextView) layout.findViewById(R.id.screen_recording_dialog_source_text)) 73 .setText(label); 74 return layout; 75 } 76 77 @Override getDropDownView(int position, View convertView, ViewGroup parent)78 public View getDropDownView(int position, View convertView, ViewGroup parent) { 79 switch (getItem(position)) { 80 case INTERNAL: 81 return getOption(R.string.screenrecord_device_audio_label, 82 R.string.screenrecord_device_audio_description); 83 case MIC_AND_INTERNAL: 84 return getOption( 85 R.string.screenrecord_device_audio_and_mic_label, Resources.ID_NULL); 86 case MIC: 87 return getOption(R.string.screenrecord_mic_label, Resources.ID_NULL); 88 default: 89 return super.getDropDownView(position, convertView, parent); 90 } 91 } 92 93 @Override getView(int position, View convertView, ViewGroup parent)94 public View getView(int position, View convertView, ViewGroup parent) { 95 switch (getItem(position)) { 96 case INTERNAL: 97 return mSelectedInternal; 98 case MIC_AND_INTERNAL: 99 return mSelectedMicAndInternal; 100 case MIC: 101 return mSelectedMic; 102 default: 103 return super.getView(position, convertView, parent); 104 } 105 } 106 } 107