1/* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11package org.webrtc.vieautotest; 12 13import org.webrtc.vieautotest.R; 14 15import android.app.Activity; 16import android.os.Bundle; 17import android.util.Log; 18import android.widget.Button; 19import android.view.SurfaceView; 20import android.view.View; 21import android.view.SurfaceHolder; 22import android.widget.LinearLayout; 23import android.opengl.GLSurfaceView; 24import android.widget.Spinner; 25import android.widget.ArrayAdapter; 26import android.widget.AdapterView; 27 28public class ViEAutotest extends Activity 29 implements 30 AdapterView.OnItemSelectedListener, 31 View.OnClickListener { 32 33 private Thread testThread; 34 private Spinner testSpinner; 35 private Spinner subtestSpinner; 36 private int testSelection; 37 private int subTestSelection; 38 39 // View for remote video 40 private LinearLayout remoteSurface = null; 41 private GLSurfaceView glSurfaceView = null; 42 private SurfaceView surfaceView = null; 43 44 private LinearLayout localSurface = null; 45 private GLSurfaceView glLocalSurfaceView = null; 46 private SurfaceView localSurfaceView = null; 47 48 /** Called when the activity is first created. */ 49 @Override 50 public void onCreate(Bundle savedInstanceState) { 51 52 Log.d("*WEBRTC*", "onCreate called"); 53 54 super.onCreate(savedInstanceState); 55 setContentView(R.layout.main); 56 57 // Set the Start button action 58 final Button buttonStart = (Button) findViewById(R.id.Button01); 59 buttonStart.setOnClickListener(this); 60 61 // Set test spinner 62 testSpinner = (Spinner) findViewById(R.id.testSpinner); 63 ArrayAdapter<CharSequence> adapter = 64 ArrayAdapter.createFromResource(this, R.array.test_array, 65 android.R.layout.simple_spinner_item); 66 67 int resource = android.R.layout.simple_spinner_dropdown_item; 68 adapter.setDropDownViewResource(resource); 69 testSpinner.setAdapter(adapter); 70 testSpinner.setOnItemSelectedListener(this); 71 72 // Set sub test spinner 73 subtestSpinner = (Spinner) findViewById(R.id.subtestSpinner); 74 ArrayAdapter<CharSequence> subtestAdapter = 75 ArrayAdapter.createFromResource(this, R.array.subtest_array, 76 android.R.layout.simple_spinner_item); 77 78 subtestAdapter.setDropDownViewResource(resource); 79 subtestSpinner.setAdapter(subtestAdapter); 80 subtestSpinner.setOnItemSelectedListener(this); 81 82 remoteSurface = (LinearLayout) findViewById(R.id.RemoteView); 83 surfaceView = new SurfaceView(this); 84 remoteSurface.addView(surfaceView); 85 86 localSurface = (LinearLayout) findViewById(R.id.LocalView); 87 localSurfaceView = new SurfaceView(this); 88 localSurfaceView.setZOrderMediaOverlay(true); 89 localSurface.addView(localSurfaceView); 90 91 // Set members 92 testSelection = 0; 93 subTestSelection = 0; 94 } 95 96 public void onClick(View v) { 97 Log.d("*WEBRTC*", "Button clicked..."); 98 switch (v.getId()) { 99 case R.id.Button01: 100 new Thread(new Runnable() { 101 public void run() { 102 Log.d("*WEBRTC*", "Calling RunTest..."); 103 RunTest(testSelection, subTestSelection, 104 localSurfaceView, surfaceView); 105 Log.d("*WEBRTC*", "RunTest done"); 106 } 107 }).start(); 108 } 109 } 110 111 public void onItemSelected(AdapterView<?> parent, View v, 112 int position, long id) { 113 114 if (parent == (Spinner) findViewById(R.id.testSpinner)) { 115 testSelection = position; 116 } else { 117 subTestSelection = position; 118 } 119 } 120 121 public void onNothingSelected(AdapterView<?> parent) { 122 } 123 124 @Override 125 protected void onStart() { 126 super.onStart(); 127 } 128 129 @Override 130 protected void onResume() { 131 super.onResume(); 132 } 133 134 @Override 135 protected void onPause() { 136 super.onPause(); 137 } 138 139 @Override 140 protected void onStop() { 141 super.onStop(); 142 } 143 144 @Override 145 protected void onDestroy() { 146 147 super.onDestroy(); 148 } 149 150 // C++ function performing the chosen test 151 // private native int RunTest(int testSelection, int subtestSelection, 152 // GLSurfaceView window1, GLSurfaceView window2); 153 private native int RunTest(int testSelection, int subtestSelection, 154 SurfaceView window1, SurfaceView window2); 155 156 // this is used to load the 'ViEAutotestJNIAPI' library on application 157 // startup. 158 static { 159 Log.d("*WEBRTC*", "Loading ViEAutotest..."); 160 System.loadLibrary("webrtc-video-autotest-jni"); 161 } 162} 163