1 /* 2 * Copyright (C) 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.android.cts.verifier.audio; 18 19 import android.app.AlertDialog; 20 import android.content.DialogInterface; 21 import android.content.res.Resources; 22 import android.graphics.Color; 23 import android.os.Bundle; 24 import android.util.Log; 25 import android.view.KeyEvent; 26 import android.widget.TextView; 27 28 import com.android.cts.verifier.audio.peripheralprofile.PeripheralProfile; 29 import com.android.cts.verifier.audio.peripheralprofile.ProfileButtonAttributes; 30 31 import com.android.cts.verifier.R; // needed to access resource in CTSVerifier project namespace. 32 33 public class USBAudioPeripheralButtonsActivity extends USBAudioPeripheralActivity { 34 private static final String TAG = "USBAudioPeripheralButtonsActivity"; 35 36 // State 37 private boolean mHasBtnA; 38 private boolean mHasBtnB; 39 private boolean mHasBtnC; 40 41 // Widgets 42 private TextView mBtnALabelTxt; 43 private TextView mBtnBLabelTxt; 44 private TextView mBtnCLabelTxt; 45 46 private TextView mBtnAStatusTxt; 47 private TextView mBtnBStatusTxt; 48 private TextView mBtnCStatusTxt; 49 USBAudioPeripheralButtonsActivity()50 public USBAudioPeripheralButtonsActivity() { 51 super(false); // Mandated peripheral is NOT required 52 } 53 showDisableAssistantDialog()54 private void showDisableAssistantDialog() { 55 AlertDialog.Builder builder = 56 new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_Alert); 57 builder.setTitle(getResources().getString(R.string.uapButtonsDisableAssistantTitle)); 58 builder.setMessage(getResources().getString(R.string.uapButtonsDisableAssistant)); 59 builder.setPositiveButton(android.R.string.yes, 60 new DialogInterface.OnClickListener() { 61 public void onClick(DialogInterface dialog, int which) {} 62 }); 63 builder.setIcon(android.R.drawable.ic_dialog_alert); 64 builder.show(); 65 } 66 67 @Override onCreate(Bundle savedInstanceState)68 protected void onCreate(Bundle savedInstanceState) { 69 super.onCreate(savedInstanceState); 70 setContentView(R.layout.uap_buttons_panel); 71 72 connectPeripheralStatusWidgets(); 73 74 mBtnALabelTxt = (TextView)findViewById(R.id.uap_buttonsBtnALabelTx); 75 mBtnBLabelTxt = (TextView)findViewById(R.id.uap_buttonsBtnBLabelTx); 76 mBtnCLabelTxt = (TextView)findViewById(R.id.uap_buttonsBtnCLabelTx); 77 78 mBtnAStatusTxt = (TextView)findViewById(R.id.uap_buttonsBtnAStatusTx); 79 mBtnBStatusTxt = (TextView)findViewById(R.id.uap_buttonsBtnBStatusTx); 80 mBtnCStatusTxt = (TextView)findViewById(R.id.uap_buttonsBtnCStatusTx); 81 82 setPassFailButtonClickListeners(); 83 setInfoResources(R.string.usbaudio_buttons_test, R.string.usbaudio_buttons_info, -1); 84 85 showDisableAssistantDialog(); 86 87 connectUSBPeripheralUI(); 88 } 89 showButtonsState()90 private void showButtonsState() { 91 int ctrlColor = mIsPeripheralAttached ? Color.WHITE : Color.GRAY; 92 mBtnALabelTxt.setTextColor(ctrlColor); 93 mBtnAStatusTxt.setTextColor(ctrlColor); 94 mBtnBLabelTxt.setTextColor(ctrlColor); 95 mBtnBStatusTxt.setTextColor(ctrlColor); 96 mBtnCLabelTxt.setTextColor(ctrlColor); 97 mBtnCStatusTxt.setTextColor(ctrlColor); 98 99 mBtnAStatusTxt.setText(getString( 100 mHasBtnA ? R.string.uapButtonsRecognized : R.string.uapButtonsNotRecognized)); 101 mBtnBStatusTxt.setText(getString( 102 mHasBtnB ? R.string.uapButtonsRecognized : R.string.uapButtonsNotRecognized)); 103 mBtnCStatusTxt.setText(getString( 104 mHasBtnC ? R.string.uapButtonsRecognized : R.string.uapButtonsNotRecognized)); 105 106 calculateMatch(); 107 } 108 calculateMatch()109 private void calculateMatch() { 110 if (mIsPeripheralAttached) { 111 boolean match = mHasBtnA && mHasBtnB && mHasBtnC; 112 Log.i(TAG, "match:" + match); 113 getPassButton().setEnabled(match); 114 } else { 115 getPassButton().setEnabled(false); 116 } 117 } 118 119 @Override onKeyDown(int keyCode, KeyEvent event)120 public boolean onKeyDown(int keyCode, KeyEvent event) { 121 // Log.i(TAG, "onKeyDown(" + keyCode + ")"); 122 switch (keyCode) { 123 // Function A control event 124 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: 125 mHasBtnA = true; 126 break; 127 128 // Function B control event 129 case KeyEvent.KEYCODE_VOLUME_UP: 130 mHasBtnB = true; 131 break; 132 133 // Function C control event 134 case KeyEvent.KEYCODE_VOLUME_DOWN: 135 mHasBtnC = true; 136 break; 137 } 138 139 showButtonsState(); 140 calculateMatch(); 141 142 return super.onKeyDown(keyCode, event); 143 } 144 145 // 146 // USBAudioPeripheralActivity 147 // updateConnectStatus()148 public void updateConnectStatus() { 149 mHasBtnA = mHasBtnB = mHasBtnC = false; 150 showButtonsState(); 151 calculateMatch(); 152 } 153 } 154 155