1 /* 2 * Copyright (C) 2007 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.camera; 18 19 import com.android.gallery.R; 20 21 22 import android.app.Activity; 23 import android.content.Intent; 24 import android.content.pm.ActivityInfo; 25 import android.os.Bundle; 26 import android.provider.MediaStore; 27 import android.util.Log; 28 import android.view.View; 29 30 /** 31 * This activity plays a video from a specified URI. 32 */ 33 public class MovieView extends NoSearchActivity { 34 private static final String TAG = "MovieView"; 35 36 private MovieViewControl mControl; 37 private boolean mFinishOnCompletion; 38 private boolean mResumed = false; // Whether this activity has been resumed. 39 private boolean mFocused = false; // Whether this window has focus. 40 private boolean mControlResumed = false; // Whether the MovieViewControl is resumed. 41 42 @Override 43 public void onCreate(Bundle icicle) { 44 super.onCreate(icicle); 45 setContentView(R.layout.movie_view); 46 View rootView = findViewById(R.id.root); 47 Intent intent = getIntent(); 48 mControl = new MovieViewControl(rootView, this, intent.getData()) { 49 @Override 50 public void onCompletion() { 51 if (mFinishOnCompletion) { 52 finish(); 53 } 54 } 55 }; 56 if (intent.hasExtra(MediaStore.EXTRA_SCREEN_ORIENTATION)) { 57 int orientation = intent.getIntExtra( 58 MediaStore.EXTRA_SCREEN_ORIENTATION, 59 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); 60 if (orientation != getRequestedOrientation()) { 61 setRequestedOrientation(orientation); 62 } 63 } 64 mFinishOnCompletion = intent.getBooleanExtra( 65 MediaStore.EXTRA_FINISH_ON_COMPLETION, true); 66 } 67 68 @Override 69 public void onPause() { 70 super.onPause(); 71 mResumed = false; 72 if (mControlResumed) { 73 mControl.onPause(); 74 mControlResumed = false; 75 } 76 } 77 78 @Override 79 public void onResume() { 80 super.onResume(); 81 mResumed = true; 82 if (mFocused && mResumed && !mControlResumed) { 83 mControl.onResume(); 84 mControlResumed = true; 85 } 86 } 87 88 @Override 89 public void onWindowFocusChanged(boolean hasFocus) { 90 mFocused = hasFocus; 91 if (mFocused && mResumed && !mControlResumed) { 92 mControl.onResume(); 93 mControlResumed = true; 94 } 95 } 96 } 97