Home | History | Annotate | Download | only in media
      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.cooliris.media;
     18 
     19 import android.app.Activity;
     20 import android.content.Intent;
     21 import android.content.pm.ActivityInfo;
     22 import android.os.Bundle;
     23 import android.provider.MediaStore;
     24 import android.view.View;
     25 import android.view.Window;
     26 import android.view.WindowManager;
     27 
     28 import com.cooliris.app.App;
     29 import com.cooliris.app.Res;
     30 
     31 /**
     32  * This activity plays a video from a specified URI.
     33  */
     34 public class MovieView extends Activity {
     35     @SuppressWarnings("unused")
     36     private static final String TAG = "MovieView";
     37 
     38     private App mApp = null;
     39     private MovieViewControl mControl;
     40     private boolean mFinishOnCompletion;
     41 
     42     @Override
     43     public void onCreate(Bundle icicle) {
     44         super.onCreate(icicle);
     45         mApp = new App(MovieView.this);
     46         setContentView(Res.layout.movie_view);
     47         View rootView = findViewById(Res.id.root);
     48         Intent intent = getIntent();
     49         mControl = new MovieViewControl(rootView, this, intent.getData()) {
     50             @Override
     51             public void onCompletion() {
     52                 if (mFinishOnCompletion) {
     53                     finish();
     54                 }
     55             }
     56         };
     57         if (intent.hasExtra(MediaStore.EXTRA_SCREEN_ORIENTATION)) {
     58             int orientation = intent.getIntExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
     59             if (orientation != getRequestedOrientation()) {
     60                 setRequestedOrientation(orientation);
     61             }
     62         }
     63         mFinishOnCompletion = intent.getBooleanExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, true);
     64         Window win = getWindow();
     65         WindowManager.LayoutParams winParams = win.getAttributes();
     66         winParams.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF;
     67         win.setAttributes(winParams);
     68     }
     69 
     70     @Override
     71     public void onPause() {
     72         mControl.onPause();
     73         super.onPause();
     74     	mApp.onPause();
     75     }
     76 
     77     @Override
     78     public void onResume() {
     79         mControl.onResume();
     80         super.onResume();
     81     	mApp.onResume();
     82     }
     83 
     84     @Override
     85     public void onDestroy() {
     86         mControl.onDestroy();
     87     	mApp.shutdown();
     88     	super.onDestroy();
     89     }
     90 }
     91