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.server.cts.device.statsd; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.os.AsyncTask; 22 import android.os.Bundle; 23 import android.os.SystemClock; 24 import android.util.Log; 25 import android.widget.VideoView; 26 27 public class VideoPlayerActivity extends Activity { 28 private static final String TAG = VideoPlayerActivity.class.getSimpleName(); 29 30 public static final String KEY_ACTION = "action"; 31 public static final String ACTION_PLAY_VIDEO = "action.play_video"; 32 public static final String ACTION_PLAY_VIDEO_PICTURE_IN_PICTURE_MODE = 33 "action.play_video_picture_in_picture_mode"; 34 35 public static final int DELAY_MILLIS = 2000; 36 37 @Override onCreate(Bundle savedInstanceState)38 public void onCreate(Bundle savedInstanceState) { 39 super.onCreate(savedInstanceState); 40 41 Intent intent = this.getIntent(); 42 if (intent == null) { 43 Log.e(TAG, "Intent was null."); 44 finish(); 45 } 46 47 String action = intent.getStringExtra(KEY_ACTION); 48 Log.i(TAG, "Starting " + action + " from foreground activity."); 49 50 switch (action) { 51 case ACTION_PLAY_VIDEO: 52 playVideo(); 53 break; 54 case ACTION_PLAY_VIDEO_PICTURE_IN_PICTURE_MODE: 55 playVideo(); 56 this.enterPictureInPictureMode(); 57 break; 58 default: 59 Log.e(TAG, "Intent had invalid action " + action); 60 finish(); 61 } 62 delay(); 63 } 64 playVideo()65 private void playVideo() { 66 setContentView(R.layout.activity_main); 67 VideoView videoView = (VideoView)findViewById(R.id.video_player_view); 68 videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.colors_video); 69 videoView.start(); 70 } 71 delay()72 private void delay() { 73 new AsyncTask<Void, Void, Void>() { 74 @Override 75 protected Void doInBackground(Void... params) { 76 SystemClock.sleep(DELAY_MILLIS); 77 return null; 78 } 79 @Override 80 protected void onPostExecute(Void nothing) { 81 finish(); 82 } 83 }.execute(); 84 } 85 } 86 87 88 89