blob: 4c9be7ef0cc03ec7a0351eb0b508a3ec8094dee9 [file] [log] [blame]
Owen Linf9a0a432011-08-17 22:07:43 +08001/*
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
17package com.android.gallery3d.app;
18
19import com.android.gallery3d.R;
20
Ray Chendcb265c2011-08-30 12:06:17 +080021import android.app.ActionBar;
Owen Linf9a0a432011-08-17 22:07:43 +080022import android.app.Activity;
23import android.content.Intent;
24import android.content.pm.ActivityInfo;
25import android.database.Cursor;
26import android.media.AudioManager;
27import android.os.Bundle;
28import android.provider.MediaStore;
29import android.provider.MediaStore.Video.VideoColumns;
30import android.view.View;
31import android.view.Window;
32import android.view.WindowManager;
33
34/**
35 * This activity plays a video from a specified URI.
36 */
37public class MovieActivity extends Activity {
38 @SuppressWarnings("unused")
39 private static final String TAG = "MovieActivity";
40
41 private MoviePlayer mPlayer;
42 private boolean mFinishOnCompletion;
43
44 @Override
45 public void onCreate(Bundle savedInstanceState) {
46 super.onCreate(savedInstanceState);
47
48 requestWindowFeature(Window.FEATURE_ACTION_BAR);
49 requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
50
51 setContentView(R.layout.movie_view);
52 View rootView = findViewById(R.id.root);
53 Intent intent = getIntent();
54 setVideoTitle(intent);
55 mPlayer = new MoviePlayer(rootView, this, intent.getData()) {
56 @Override
57 public void onCompletion() {
58 if (mFinishOnCompletion) {
59 finish();
60 }
61 }
62 };
63 if (intent.hasExtra(MediaStore.EXTRA_SCREEN_ORIENTATION)) {
64 int orientation = intent.getIntExtra(
65 MediaStore.EXTRA_SCREEN_ORIENTATION,
66 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
67 if (orientation != getRequestedOrientation()) {
68 setRequestedOrientation(orientation);
69 }
70 }
71 mFinishOnCompletion = intent.getBooleanExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, true);
72 Window win = getWindow();
73 WindowManager.LayoutParams winParams = win.getAttributes();
74 winParams.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF;
75 win.setAttributes(winParams);
76
77 }
78
79 private void setVideoTitle(Intent intent) {
80 String title = intent.getStringExtra(Intent.EXTRA_TITLE);
81 if (title == null) {
82 Cursor cursor = null;
83 try {
84 cursor = getContentResolver().query(intent.getData(),
85 new String[] {VideoColumns.TITLE}, null, null, null);
86 if (cursor != null && cursor.moveToNext()) {
87 title = cursor.getString(0);
88 }
89 } catch (Throwable t) {
90 Log.w(TAG, "cannot get title from: " + intent.getDataString(), t);
91 } finally {
92 if (cursor != null) cursor.close();
93 }
94 }
Ray Chendcb265c2011-08-30 12:06:17 +080095 ActionBar actionBar = getActionBar();
96 if (title != null && actionBar != null) actionBar.setTitle(title);
Owen Linf9a0a432011-08-17 22:07:43 +080097 }
98
99 @Override
100 public void onStart() {
101 ((AudioManager) getSystemService(AUDIO_SERVICE))
102 .requestAudioFocus(null, AudioManager.STREAM_MUSIC,
103 AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
104 super.onStart();
105 }
106
107 @Override
108 protected void onStop() {
109 ((AudioManager) getSystemService(AUDIO_SERVICE))
110 .abandonAudioFocus(null);
111 super.onStop();
112 }
113
114 @Override
115 public void onPause() {
116 mPlayer.onPause();
117 super.onPause();
118 }
119
120 @Override
121 public void onResume() {
122 mPlayer.onResume();
123 super.onResume();
124 }
125
126 @Override
127 public void onDestroy() {
128 mPlayer.onDestroy();
129 super.onDestroy();
130 }
131}