Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 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.gallery3d.app; |
| 18 | |
Ray Chen | dcb265c | 2011-08-30 12:06:17 +0800 | [diff] [blame] | 19 | import android.app.ActionBar; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 20 | import android.app.Activity; |
| 21 | import android.content.Intent; |
| 22 | import android.content.pm.ActivityInfo; |
| 23 | import android.database.Cursor; |
| 24 | import android.media.AudioManager; |
Ray Chen | e6e4beb | 2011-10-11 11:37:18 +0800 | [diff] [blame] | 25 | import android.net.Uri; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 26 | import android.os.Bundle; |
| 27 | import android.provider.MediaStore; |
| 28 | import android.provider.MediaStore.Video.VideoColumns; |
Chih-Chung Chang | fc8c503 | 2011-11-29 14:21:11 +0800 | [diff] [blame] | 29 | import android.view.KeyEvent; |
Ray Chen | e6e4beb | 2011-10-11 11:37:18 +0800 | [diff] [blame] | 30 | import android.view.Menu; |
Chih-Chung Chang | bb7d7b9 | 2011-09-21 15:38:35 +0800 | [diff] [blame] | 31 | import android.view.MenuItem; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 32 | import android.view.View; |
| 33 | import android.view.Window; |
| 34 | import android.view.WindowManager; |
Ray Chen | e6e4beb | 2011-10-11 11:37:18 +0800 | [diff] [blame] | 35 | import android.widget.ShareActionProvider; |
| 36 | |
| 37 | import com.android.gallery3d.R; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * This activity plays a video from a specified URI. |
| 41 | */ |
| 42 | public class MovieActivity extends Activity { |
| 43 | @SuppressWarnings("unused") |
| 44 | private static final String TAG = "MovieActivity"; |
| 45 | |
| 46 | private MoviePlayer mPlayer; |
| 47 | private boolean mFinishOnCompletion; |
Ray Chen | e6e4beb | 2011-10-11 11:37:18 +0800 | [diff] [blame] | 48 | private Uri mUri; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 49 | |
| 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 Chang | bb7d7b9 | 2011-09-21 15:38:35 +0800 | [diff] [blame] | 60 | initializeActionBar(intent); |
Chih-Chung Chang | 209a916 | 2011-10-14 16:09:09 +0800 | [diff] [blame] | 61 | mFinishOnCompletion = intent.getBooleanExtra( |
| 62 | MediaStore.EXTRA_FINISH_ON_COMPLETION, true); |
| 63 | mPlayer = new MoviePlayer(rootView, this, intent.getData(), savedInstanceState, |
| 64 | !mFinishOnCompletion) { |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 65 | @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 Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 80 | Window win = getWindow(); |
| 81 | WindowManager.LayoutParams winParams = win.getAttributes(); |
| 82 | winParams.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF; |
Chih-Chung Chang | 8176012 | 2011-09-27 16:50:16 +0800 | [diff] [blame] | 83 | winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 84 | win.setAttributes(winParams); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 85 | } |
| 86 | |
Chih-Chung Chang | bb7d7b9 | 2011-09-21 15:38:35 +0800 | [diff] [blame] | 87 | private void initializeActionBar(Intent intent) { |
Pin Ting | 143594f | 2012-01-18 18:15:27 +0800 | [diff] [blame^] | 88 | mUri = intent.getData(); |
Chih-Chung Chang | bb7d7b9 | 2011-09-21 15:38:35 +0800 | [diff] [blame] | 89 | ActionBar actionBar = getActionBar(); |
| 90 | actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, |
| 91 | ActionBar.DISPLAY_HOME_AS_UP); |
Pin Ting | 143594f | 2012-01-18 18:15:27 +0800 | [diff] [blame^] | 92 | |
| 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 Chang | bb7d7b9 | 2011-09-21 15:38:35 +0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
Ray Chen | e6e4beb | 2011-10-11 11:37:18 +0800 | [diff] [blame] | 100 | 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 Chang | bb7d7b9 | 2011-09-21 15:38:35 +0800 | [diff] [blame] | 117 | public boolean onOptionsItemSelected(MenuItem item) { |
| 118 | if (item.getItemId() == android.R.id.home) { |
| 119 | finish(); |
| 120 | return true; |
| 121 | } |
| 122 | return false; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 123 | } |
| 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 Lin | 540e469 | 2011-09-14 19:49:03 +0800 | [diff] [blame] | 153 | public void onSaveInstanceState(Bundle outState) { |
| 154 | super.onSaveInstanceState(outState); |
| 155 | mPlayer.onSaveInstanceState(outState); |
| 156 | } |
| 157 | |
| 158 | @Override |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 159 | public void onDestroy() { |
| 160 | mPlayer.onDestroy(); |
| 161 | super.onDestroy(); |
| 162 | } |
Chih-Chung Chang | fc8c503 | 2011-11-29 14:21:11 +0800 | [diff] [blame] | 163 | |
| 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 Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 175 | } |