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.vr; 17 18 import android.app.Activity; 19 import android.content.ComponentName; 20 import android.content.Intent; 21 import android.content.pm.PackageManager; 22 import android.os.Bundle; 23 import android.os.Handler; 24 import android.util.Log; 25 26 public class MockVrActivity extends Activity { 27 private static final String TAG = "MockVrActivity"; 28 static final int EVENT_DELAY_MS = 1000; 29 private boolean mDoSecondIntent; 30 private Handler mHandler; 31 32 @Override 33 protected void onCreate(Bundle savedInstanceState) { 34 Log.i(TAG, "onCreate called."); 35 super.onCreate(savedInstanceState); 36 try { 37 setVrModeEnabled(true, new ComponentName(this, MockVrListenerService.class)); 38 } catch (PackageManager.NameNotFoundException e) { 39 Log.e(TAG, "Could not set VR mode: " + e); 40 } 41 mDoSecondIntent = getIntent().getBooleanExtra( 42 VrListenerVerifierActivity.EXTRA_LAUNCH_SECOND_INTENT, false); 43 mHandler = new Handler(); 44 } 45 46 @Override 47 protected void onResume() { 48 Log.i(TAG, "onResume called."); 49 50 super.onResume(); 51 if (mDoSecondIntent) { 52 mDoSecondIntent = false; 53 mHandler.postDelayed(new Runnable() { 54 @Override 55 public void run() { 56 MockVrActivity.this.startActivity(new Intent(MockVrActivity.this, 57 MockVrActivity2.class)); 58 } 59 }, EVENT_DELAY_MS); 60 } else { 61 mHandler.postDelayed(new Runnable() { 62 @Override 63 public void run() { 64 MockVrActivity.this.finish(); 65 } 66 }, EVENT_DELAY_MS); 67 } 68 } 69 70 @Override 71 public void onWindowFocusChanged(boolean hasFocus) { 72 Log.i(TAG, "onWindowFocusChanged called with " + hasFocus); 73 super.onWindowFocusChanged(hasFocus); 74 } 75 76 @Override 77 protected void onPause() { 78 Log.i(TAG, "onPause called."); 79 super.onPause(); 80 } 81 } 82