1 /*
2  * Copyright (C) 2022 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.cts.verifier.audio;
18 
19 import android.os.Bundle;
20 import android.view.View;
21 import android.widget.RadioButton;
22 
23 import com.android.cts.verifier.PassFailButtons;
24 import com.android.cts.verifier.R;
25 
26 // MegaAudio
27 import org.hyphonate.megaaudio.common.BuilderBase;
28 
29 abstract class AudioMultiApiActivity
30         extends PassFailButtons.Activity
31         implements View.OnClickListener {
32     private static final String TAG = "AudioMultiApiActivity";
33 
34     protected int mAudioApi = BuilderBase.TYPE_OBOE | BuilderBase.SUB_TYPE_OBOE_AAUDIO;
35 
36     // Test API (back-end) IDs
37     protected static final int NUM_TEST_APIS = 2;
38     protected static final int TEST_API_NATIVE = 0;
39     protected static final int TEST_API_JAVA = 1;
40     protected int mActiveTestAPI = TEST_API_NATIVE;
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45 
46         ((RadioButton) findViewById(R.id.audioJavaApiBtn)).setOnClickListener(this);
47         RadioButton nativeApiRB = findViewById(R.id.audioNativeApiBtn);
48         nativeApiRB.setChecked(true);
49         nativeApiRB.setOnClickListener(this);
50     }
51 
52     @Override
setTestResultAndFinish(boolean passed)53     public void setTestResultAndFinish(boolean passed) {
54         super.setTestResultAndFinish(passed);
55     }
56 
onApiChange(int api)57     public abstract void onApiChange(int api);
58 
59     //
60     // View.OnClickListener
61     //
62     @Override
onClick(View view)63     public void onClick(View view) {
64         int id = view.getId();
65         if (id == R.id.audioJavaApiBtn) {
66             mAudioApi = BuilderBase.TYPE_JAVA;
67             onApiChange(mActiveTestAPI = TEST_API_JAVA);
68         } else if (id == R.id.audioNativeApiBtn) {
69             mAudioApi = BuilderBase.TYPE_OBOE | BuilderBase.SUB_TYPE_OBOE_AAUDIO;
70             onApiChange(mActiveTestAPI = TEST_API_NATIVE);
71         }
72     }
73 }
74