blob: ed85582c04d2c15f21391cda8a0cb4547df4a4d9 [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
Ray Chendcb265c2011-08-30 12:06:17 +080019import android.app.ActionBar;
Owen Linf9a0a432011-08-17 22:07:43 +080020import android.app.Activity;
21import android.content.Intent;
22import android.content.pm.ActivityInfo;
23import android.database.Cursor;
24import android.media.AudioManager;
Ray Chene6e4beb2011-10-11 11:37:18 +080025import android.net.Uri;
Owen Linf9a0a432011-08-17 22:07:43 +080026import android.os.Bundle;
27import android.provider.MediaStore;
28import android.provider.MediaStore.Video.VideoColumns;
Chih-Chung Changfc8c5032011-11-29 14:21:11 +080029import android.view.KeyEvent;
Ray Chene6e4beb2011-10-11 11:37:18 +080030import android.view.Menu;
Chih-Chung Changbb7d7b92011-09-21 15:38:35 +080031import android.view.MenuItem;
Owen Linf9a0a432011-08-17 22:07:43 +080032import android.view.View;
33import android.view.Window;
34import android.view.WindowManager;
Ray Chene6e4beb2011-10-11 11:37:18 +080035import android.widget.ShareActionProvider;
36
37import com.android.gallery3d.R;
Owen Linf9a0a432011-08-17 22:07:43 +080038
39/**
40 * This activity plays a video from a specified URI.
41 */
42public class MovieActivity extends Activity {
43 @SuppressWarnings("unused")
44 private static final String TAG = "MovieActivity";
45
46 private MoviePlayer mPlayer;
47 private boolean mFinishOnCompletion;
Ray Chene6e4beb2011-10-11 11:37:18 +080048 private Uri mUri;
Owen Linf9a0a432011-08-17 22:07:43 +080049
50 @Override
51 public void onCreate(Bundle savedInstanceState) {
52 super.onCreate(savedInstanceState);
53
54 requestWindowFeature(Window.FEATURE_ACTION_BAR);
55 requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
56
57 setContentView(R.layout.movie_view);
58 View rootView = findViewById(R.id.root);
59 Intent intent = getIntent();
Chih-Chung Changbb7d7b92011-09-21 15:38:35 +080060 initializeActionBar(intent);
Chih-Chung Chang209a9162011-10-14 16:09:09 +080061 mFinishOnCompletion = intent.getBooleanExtra(
62 MediaStore.EXTRA_FINISH_ON_COMPLETION, true);
63 mPlayer = new MoviePlayer(rootView, this, intent.getData(), savedInstanceState,
64 !mFinishOnCompletion) {
Owen Linf9a0a432011-08-17 22:07:43 +080065 @Override
66 public void onCompletion() {
67 if (mFinishOnCompletion) {
68 finish();
69 }
70 }
71 };
72 if (intent.hasExtra(MediaStore.EXTRA_SCREEN_ORIENTATION)) {
73 int orientation = intent.getIntExtra(
74 MediaStore.EXTRA_SCREEN_ORIENTATION,
75 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
76 if (orientation != getRequestedOrientation()) {
77 setRequestedOrientation(orientation);
78 }
79 }
Owen Linf9a0a432011-08-17 22:07:43 +080080 Window win = getWindow();
81 WindowManager.LayoutParams winParams = win.getAttributes();
82 winParams.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF;
Chih-Chung Chang81760122011-09-27 16:50:16 +080083 winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
Owen Linf9a0a432011-08-17 22:07:43 +080084 win.setAttributes(winParams);
Owen Linf9a0a432011-08-17 22:07:43 +080085 }
86
Chih-Chung Changbb7d7b92011-09-21 15:38:35 +080087 private void initializeActionBar(Intent intent) {
Pin Ting143594f2012-01-18 18:15:27 +080088 mUri = intent.getData();
Chih-Chung Changbb7d7b92011-09-21 15:38:35 +080089 ActionBar actionBar = getActionBar();
90 actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP,
91 ActionBar.DISPLAY_HOME_AS_UP);
Pin Ting143594f2012-01-18 18:15:27 +080092
93 // Displays the filename as title, which is passed through intent from other apps.
94 // If other apps don't set this value, just display empty string.
95 final String title = intent.getStringExtra(Intent.EXTRA_TITLE);
96 actionBar.setTitle((title != null) ? title : "");
Chih-Chung Changbb7d7b92011-09-21 15:38:35 +080097 }
98
99 @Override
Ray Chene6e4beb2011-10-11 11:37:18 +0800100 public boolean onCreateOptionsMenu(Menu menu) {
101 super.onCreateOptionsMenu(menu);
102
103 getMenuInflater().inflate(R.menu.movie, menu);
104 ShareActionProvider provider = GalleryActionBar.initializeShareActionProvider(menu);
105
106 if (provider != null) {
107 Intent intent = new Intent(Intent.ACTION_SEND);
108 intent.setType("video/*");
109 intent.putExtra(Intent.EXTRA_STREAM, mUri);
110 provider.setShareIntent(intent);
111 }
112
113 return true;
114 }
115
116 @Override
Chih-Chung Changbb7d7b92011-09-21 15:38:35 +0800117 public boolean onOptionsItemSelected(MenuItem item) {
118 if (item.getItemId() == android.R.id.home) {
119 finish();
120 return true;
121 }
122 return false;
Owen Linf9a0a432011-08-17 22:07:43 +0800123 }
124
125 @Override
126 public void onStart() {
127 ((AudioManager) getSystemService(AUDIO_SERVICE))
128 .requestAudioFocus(null, AudioManager.STREAM_MUSIC,
129 AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
130 super.onStart();
131 }
132
133 @Override
134 protected void onStop() {
135 ((AudioManager) getSystemService(AUDIO_SERVICE))
136 .abandonAudioFocus(null);
137 super.onStop();
138 }
139
140 @Override
141 public void onPause() {
142 mPlayer.onPause();
143 super.onPause();
144 }
145
146 @Override
147 public void onResume() {
148 mPlayer.onResume();
149 super.onResume();
150 }
151
152 @Override
Owen Lin540e4692011-09-14 19:49:03 +0800153 public void onSaveInstanceState(Bundle outState) {
154 super.onSaveInstanceState(outState);
155 mPlayer.onSaveInstanceState(outState);
156 }
157
158 @Override
Owen Linf9a0a432011-08-17 22:07:43 +0800159 public void onDestroy() {
160 mPlayer.onDestroy();
161 super.onDestroy();
162 }
Chih-Chung Changfc8c5032011-11-29 14:21:11 +0800163
164 @Override
165 public boolean onKeyDown(int keyCode, KeyEvent event) {
166 return mPlayer.onKeyDown(keyCode, event)
167 || super.onKeyDown(keyCode, event);
168 }
169
170 @Override
171 public boolean onKeyUp(int keyCode, KeyEvent event) {
172 return mPlayer.onKeyUp(keyCode, event)
173 || super.onKeyUp(keyCode, event);
174 }
Owen Linf9a0a432011-08-17 22:07:43 +0800175}