1 /* 2 * Copyright (C) 2014 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.tv; 18 19 import com.android.cts.verifier.PassFailButtons; 20 import com.android.cts.verifier.R; 21 22 import android.content.Intent; 23 import android.media.tv.TvContract; 24 import android.os.Bundle; 25 import android.view.LayoutInflater; 26 import android.view.View; 27 import android.view.ViewGroup; 28 import android.widget.Button; 29 import android.widget.ImageView; 30 import android.widget.TextView; 31 32 /** 33 * Base class for TV app tests. 34 */ 35 public abstract class TvAppVerifierActivity extends PassFailButtons.Activity { 36 private static final String TAG = "TvAppVerifierActivity"; 37 38 private LayoutInflater mInflater; 39 private ViewGroup mItemList; 40 private View mPostTarget; 41 getPostTarget()42 protected View getPostTarget() { 43 return mPostTarget; 44 } 45 46 @Override onCreate(Bundle savedInstanceState)47 protected void onCreate(Bundle savedInstanceState) { 48 super.onCreate(savedInstanceState); 49 50 mInflater = getLayoutInflater(); 51 // Reusing location_mode_main. 52 View view = mInflater.inflate(R.layout.location_mode_main, null); 53 mPostTarget = mItemList = (ViewGroup) view.findViewById(R.id.test_items); 54 createTestItems(); 55 setContentView(view); 56 setPassFailButtonClickListeners(); 57 setInfoResources(); 58 59 getPassButton().setEnabled(false); 60 } 61 setButtonEnabled(View item, boolean enabled)62 protected void setButtonEnabled(View item, boolean enabled) { 63 View button = item.findViewById(R.id.user_action_button); 64 button.setFocusable(enabled); 65 button.setClickable(enabled); 66 button.setEnabled(enabled); 67 } 68 setPassState(View item, boolean passed)69 protected void setPassState(View item, boolean passed) { 70 ImageView status = (ImageView) item.findViewById(R.id.status); 71 status.setImageResource(passed ? R.drawable.fs_good : R.drawable.fs_error); 72 setButtonEnabled(item, false); 73 status.invalidate(); 74 } 75 createTestItems()76 protected abstract void createTestItems(); 77 setInfoResources()78 protected abstract void setInfoResources(); 79 80 /** 81 * Call this to create a test step where the user must perform some action. 82 */ createUserItem(int instructionTextId, int buttonTextId, View.OnClickListener l)83 protected View createUserItem(int instructionTextId, int buttonTextId, View.OnClickListener l) { 84 View item = mInflater.inflate(R.layout.tv_item, mItemList, false); 85 TextView instructions = (TextView) item.findViewById(R.id.instructions); 86 instructions.setText(instructionTextId); 87 Button button = (Button) item.findViewById(R.id.user_action_button); 88 button.setVisibility(View.VISIBLE); 89 button.setText(buttonTextId); 90 button.setOnClickListener(l); 91 mItemList.addView(item); 92 return item; 93 } 94 95 /** 96 * Call this to create a test step where the test automatically evaluates whether 97 * an expected condition is satisfied. 98 */ createAutoItem(int stringId)99 protected View createAutoItem(int stringId) { 100 View item = mInflater.inflate(R.layout.tv_item, mItemList, false); 101 TextView instructions = (TextView) item.findViewById(R.id.instructions); 102 instructions.setText(stringId); 103 mItemList.addView(item); 104 return item; 105 } 106 107 /** 108 * Call this to create alternative choice for the previous test step. 109 */ createButtonItem(int buttonTextId, View.OnClickListener l)110 protected View createButtonItem(int buttonTextId, View.OnClickListener l) { 111 View item = mInflater.inflate(R.layout.tv_item, mItemList, false); 112 Button button = (Button) item.findViewById(R.id.user_action_button); 113 button.setVisibility(View.VISIBLE); 114 button.setText(buttonTextId); 115 button.setOnClickListener(l); 116 ImageView status = (ImageView) item.findViewById(R.id.status); 117 status.setVisibility(View.INVISIBLE); 118 TextView instructions = (TextView) item.findViewById(R.id.instructions); 119 instructions.setVisibility(View.GONE); 120 mItemList.addView(item); 121 return item; 122 } 123 containsButton(View item, View button)124 static boolean containsButton(View item, View button) { 125 return item == null ? false : item.findViewById(R.id.user_action_button) == button; 126 } 127 } 128