1 /* 2 * Copyright (C) 2016 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 package com.android.cts.verifier.sensors.sixdof.Activities; 17 18 import com.android.cts.verifier.PassFailButtons; 19 import com.android.cts.verifier.R; 20 import com.android.cts.verifier.sensors.sixdof.Utils.ReportExporter; 21 22 import android.content.Context; 23 import android.content.Intent; 24 import android.os.Bundle; 25 import android.app.Activity; 26 import android.hardware.Sensor; 27 import android.hardware.SensorManager; 28 import android.view.View; 29 import android.widget.Button; 30 import android.widget.Toast; 31 32 /** 33 * Launcher activity that gives brief instructions of tests. 34 */ 35 public class StartActivity extends PassFailButtons.Activity { 36 private Button mBtnStart; 37 38 // Unique code that ensures we get the result from the activity that want to get a result 39 private static final int REQUEST_CODE_6DOF = 5555; 40 41 public enum ResultCode { 42 FAILED_PAUSE_AND_RESUME, 43 FAILED, 44 PASSED 45 } 46 47 @Override onCreate(Bundle savedInstanceState)48 protected void onCreate(Bundle savedInstanceState) { 49 super.onCreate(savedInstanceState); 50 setContentView(R.layout.activity_start); 51 52 mBtnStart = (Button) findViewById(R.id.btnStart); 53 mBtnStart.setOnClickListener(new View.OnClickListener() { 54 @Override 55 public void onClick(View view) { 56 startPhase1(); 57 } 58 }); 59 60 // If there is no 6DoF sensor advertised, pass trivially. 61 SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); 62 if (sensorManager.getDefaultSensor(Sensor.TYPE_POSE_6DOF) == null) { 63 StartActivity.this.setTestResultAndFinish(true); 64 } 65 } 66 67 @Override onResume()68 protected void onResume() { 69 super.onResume(); 70 } 71 startPhase1()72 private void startPhase1() { 73 Intent startPhase1 = new Intent(this, TestActivity.class); 74 startActivityForResult(startPhase1, REQUEST_CODE_6DOF); 75 } 76 77 @Override onActivityResult(int requestCode, int resultCode, Intent data)78 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 79 // Check which request we're responding to. 80 if (requestCode == REQUEST_CODE_6DOF) { 81 if (resultCode == RESULT_CANCELED) { 82 Toast.makeText(this, R.string.test_failed, Toast.LENGTH_SHORT).show(); 83 } else { // RESULT_OK 84 ResultCode result = (ResultCode) data.getSerializableExtra(TestActivity.EXTRA_RESULT_ID); 85 if (result == ResultCode.FAILED_PAUSE_AND_RESUME) { 86 Toast.makeText(this, R.string.failed_pause_resume, Toast.LENGTH_SHORT).show(); 87 } else if (result == ResultCode.FAILED) { 88 Toast.makeText(this, R.string.failed, Toast.LENGTH_SHORT).show(); 89 } else if (result == ResultCode.PASSED) { 90 Toast.makeText(this, R.string.passed, Toast.LENGTH_SHORT).show(); 91 } 92 93 String testReport = data.getStringExtra(TestActivity.EXTRA_REPORT); 94 new ReportExporter(this, testReport).execute(); 95 } 96 } 97 } 98 } 99