1 /*
2  * Copyright 2017 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.google.sample.oboe.manualtest;
18 
19 import android.os.Bundle;
20 import android.view.View;
21 import android.widget.AdapterView;
22 import android.widget.CheckBox;
23 import android.widget.Spinner;
24 
25 import java.io.IOException;
26 
27 /**
28  * Test basic output.
29  */
30 public final class TestOutputActivity extends TestOutputActivityBase {
31 
32     public static final int MAX_CHANNEL_BOXES = 8;
33     private CheckBox[] mChannelBoxes;
34     private Spinner mNativeApiSpinner;
35 
36     private class NativeApiSpinnerListener implements android.widget.AdapterView.OnItemSelectedListener {
37         @Override
onItemSelected(AdapterView<?> parent, View view, int pos, long id)38         public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
39             mAudioOutTester.setSignalType(pos);
40         }
41 
42         @Override
onNothingSelected(AdapterView<?> parent)43         public void onNothingSelected(AdapterView<?> parent) {
44             mAudioOutTester.setSignalType(0);
45         }
46     }
47 
48     @Override
inflateActivity()49     protected void inflateActivity() {
50         setContentView(R.layout.activity_test_output);
51     }
52 
53     @Override
onCreate(Bundle savedInstanceState)54     protected void onCreate(Bundle savedInstanceState) {
55         super.onCreate(savedInstanceState);
56 
57         updateEnabledWidgets();
58 
59         mAudioOutTester = addAudioOutputTester();
60 
61         mChannelBoxes = new CheckBox[MAX_CHANNEL_BOXES];
62         int ic = 0;
63         mChannelBoxes[ic++] = (CheckBox) findViewById(R.id.channelBox0);
64         mChannelBoxes[ic++] = (CheckBox) findViewById(R.id.channelBox1);
65         mChannelBoxes[ic++] = (CheckBox) findViewById(R.id.channelBox2);
66         mChannelBoxes[ic++] = (CheckBox) findViewById(R.id.channelBox3);
67         mChannelBoxes[ic++] = (CheckBox) findViewById(R.id.channelBox4);
68         mChannelBoxes[ic++] = (CheckBox) findViewById(R.id.channelBox5);
69         mChannelBoxes[ic++] = (CheckBox) findViewById(R.id.channelBox6);
70         mChannelBoxes[ic++] = (CheckBox) findViewById(R.id.channelBox7);
71         configureChannelBoxes(0);
72 
73         mNativeApiSpinner = (Spinner) findViewById(R.id.spinnerOutputSignal);
74         mNativeApiSpinner.setOnItemSelectedListener(new NativeApiSpinnerListener());
75         mNativeApiSpinner.setSelection(StreamConfiguration.NATIVE_API_UNSPECIFIED);
76     }
77 
78     @Override
getActivityType()79     int getActivityType() {
80         return ACTIVITY_TEST_OUTPUT;
81     }
82 
openAudio()83     public void openAudio() throws IOException {
84         super.openAudio();
85         int channelCount = mAudioOutTester.getCurrentAudioStream().getChannelCount();
86         configureChannelBoxes(channelCount);
87     }
88 
configureChannelBoxes(int channelCount)89     private void configureChannelBoxes(int channelCount) {
90         for (int i = 0; i < mChannelBoxes.length; i++) {
91             mChannelBoxes[i].setChecked(i < channelCount);
92             mChannelBoxes[i].setEnabled(i < channelCount);
93         }
94     }
95 
96     public void closeAudio() {
97         configureChannelBoxes(0);
98         super.closeAudio();
99     }
100 
101     public void onChannelBoxClicked(View view) {
102         CheckBox checkBox = (CheckBox) view;
103         String text = (String) checkBox.getText();
104         int channelIndex = Integer.parseInt(text);
105         mAudioOutTester.setChannelEnabled(channelIndex, checkBox.isChecked());
106     }
107 }
108