CameraActivity.java revision ff33b520b30a3faf72623f2889fdae1096a8586b
1/* 2 * Copyright (C) 2012 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.camera; 18 19import android.app.AlertDialog; 20import android.animation.Animator; 21import android.annotation.TargetApi; 22import android.app.ActionBar; 23import android.app.Activity; 24import android.content.ActivityNotFoundException; 25import android.content.BroadcastReceiver; 26import android.content.ContentResolver; 27import android.content.Context; 28import android.content.Intent; 29import android.content.IntentFilter; 30import android.content.SharedPreferences; 31import android.content.pm.ActivityInfo; 32import android.content.res.Configuration; 33import android.graphics.Bitmap; 34import android.graphics.Color; 35import android.graphics.SurfaceTexture; 36import android.graphics.drawable.ColorDrawable; 37import android.net.Uri; 38import android.nfc.NfcAdapter; 39import android.nfc.NfcAdapter.CreateBeamUrisCallback; 40import android.nfc.NfcEvent; 41import android.os.AsyncTask; 42import android.os.Build; 43import android.os.Bundle; 44import android.os.Handler; 45import android.os.Looper; 46import android.os.Message; 47import android.preference.PreferenceManager; 48import android.provider.MediaStore; 49import android.provider.Settings; 50import android.util.Log; 51import android.view.Gravity; 52import android.view.KeyEvent; 53import android.view.LayoutInflater; 54import android.view.Menu; 55import android.view.MenuInflater; 56import android.view.MenuItem; 57import android.view.MotionEvent; 58import android.view.View; 59import android.view.ViewGroup; 60import android.view.Window; 61import android.view.WindowManager; 62import android.widget.FrameLayout; 63import android.widget.FrameLayout.LayoutParams; 64import android.widget.ImageView; 65import android.widget.PopupWindow; 66import android.widget.ProgressBar; 67import android.widget.ShareActionProvider; 68 69import com.android.camera.app.AppController; 70import com.android.camera.app.AppManagerFactory; 71import com.android.camera.app.CameraAppUI; 72import com.android.camera.app.CameraController; 73import com.android.camera.app.CameraManager; 74import com.android.camera.app.CameraManagerFactory; 75import com.android.camera.app.CameraProvider; 76import com.android.camera.app.CameraServices; 77import com.android.camera.app.ImageTaskManager; 78import com.android.camera.app.MediaSaver; 79import com.android.camera.app.ModuleManagerImpl; 80import com.android.camera.app.OrientationManager; 81import com.android.camera.app.OrientationManagerImpl; 82import com.android.camera.app.PanoramaStitchingManager; 83import com.android.camera.app.PlaceholderManager; 84import com.android.camera.crop.CropActivity; 85import com.android.camera.data.CameraDataAdapter; 86import com.android.camera.data.CameraPreviewData; 87import com.android.camera.data.FixedFirstDataAdapter; 88import com.android.camera.data.FixedLastDataAdapter; 89import com.android.camera.data.InProgressDataWrapper; 90import com.android.camera.data.LocalData; 91import com.android.camera.data.LocalDataAdapter; 92import com.android.camera.data.LocalMediaObserver; 93import com.android.camera.data.MediaDetails; 94import com.android.camera.data.SimpleViewData; 95import com.android.camera.filmstrip.FilmstripController; 96import com.android.camera.filmstrip.FilmstripImageData; 97import com.android.camera.filmstrip.FilmstripListener; 98import com.android.camera.module.ModulesInfo; 99import com.android.camera.settings.SettingsManager; 100import com.android.camera.settings.SettingsManager.SettingsCapabilities; 101import com.android.camera.tinyplanet.TinyPlanetFragment; 102import com.android.camera.ui.CameraControls; 103import com.android.camera.ui.DetailsDialog; 104import com.android.camera.ui.FilmstripView; 105import com.android.camera.ui.MainActivityLayout; 106import com.android.camera.ui.ModeListView; 107import com.android.camera.ui.SettingsView; 108import com.android.camera.util.ApiHelper; 109import com.android.camera.util.CameraUtil; 110import com.android.camera.util.FeedbackHelper; 111import com.android.camera.util.GcamHelper; 112import com.android.camera.util.IntentHelper; 113import com.android.camera.util.PhotoSphereHelper.PanoramaViewHelper; 114import com.android.camera.util.UsageStatistics; 115import com.android.camera2.R; 116 117import java.io.File; 118 119public class CameraActivity extends Activity 120 implements AppController, CameraManager.CameraOpenCallback, 121 ActionBar.OnMenuVisibilityListener, ShareActionProvider.OnShareTargetSelectedListener, 122 OrientationManager.OnOrientationChangeListener { 123 124 private static final String TAG = "CAM_Activity"; 125 126 private static final String INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE = 127 "android.media.action.STILL_IMAGE_CAMERA_SECURE"; 128 public static final String ACTION_IMAGE_CAPTURE_SECURE = 129 "android.media.action.IMAGE_CAPTURE_SECURE"; 130 public static final String ACTION_TRIM_VIDEO = 131 "com.android.camera.action.TRIM"; 132 public static final String MEDIA_ITEM_PATH = "media-item-path"; 133 134 // The intent extra for camera from secure lock screen. True if the gallery 135 // should only show newly captured pictures. sSecureAlbumId does not 136 // increment. This is used when switching between camera, camcorder, and 137 // panorama. If the extra is not set, it is in the normal camera mode. 138 public static final String SECURE_CAMERA_EXTRA = "secure_camera"; 139 140 /** 141 * Request code from an activity we started that indicated that we do not want 142 * to reset the view to the preview in onResume. 143 */ 144 public static final int REQ_CODE_DONT_SWITCH_TO_PREVIEW = 142; 145 146 public static final int REQ_CODE_GCAM_DEBUG_POSTCAPTURE = 999; 147 148 private static final int MSG_HIDE_ACTION_BAR = 1; 149 private static final int MSG_CLEAR_SCREEN_ON_FLAG = 2; 150 private static final long SHOW_ACTION_BAR_TIMEOUT_MS = 3000; 151 private static final long SCREEN_DELAY_MS = 2 * 60 * 1000; // 2 mins. 152 153 /** 154 * Whether onResume should reset the view to the preview. 155 */ 156 private boolean mResetToPreviewOnResume = true; 157 158 // Supported operations at FilmStripView. Different data has different 159 // set of supported operations. 160 private static final int SUPPORT_DELETE = 1 << 0; 161 private static final int SUPPORT_ROTATE = 1 << 1; 162 private static final int SUPPORT_INFO = 1 << 2; 163 private static final int SUPPORT_CROP = 1 << 3; 164 private static final int SUPPORT_SETAS = 1 << 4; 165 private static final int SUPPORT_EDIT = 1 << 5; 166 private static final int SUPPORT_TRIM = 1 << 6; 167 private static final int SUPPORT_SHARE = 1 << 7; 168 private static final int SUPPORT_SHARE_PANORAMA360 = 1 << 8; 169 private static final int SUPPORT_SHOW_ON_MAP = 1 << 9; 170 private static final int SUPPORT_ALL = 0xffffffff; 171 172 /** 173 * This data adapter is used by FilmStripView. 174 */ 175 private LocalDataAdapter mDataAdapter; 176 /** 177 * This data adapter represents the real local camera data. 178 */ 179 private LocalDataAdapter mWrappedDataAdapter; 180 181 private SettingsManager mSettingsManager; 182 private SettingsController mSettingsController; 183 private PanoramaStitchingManager mPanoramaManager; 184 private PlaceholderManager mPlaceholderManager; 185 private ModeListView mModeListView; 186 private int mCurrentModeIndex; 187 private CameraModule mCurrentModule; 188 private ModuleManagerImpl mModuleManager; 189 private FrameLayout mAboveFilmstripControlLayout; 190 private FrameLayout mCameraModuleRootView; 191 private FilmstripController mFilmstripController; 192 private ProgressBar mBottomProgress; 193 private View mPanoStitchingPanel; 194 private int mResultCodeForTesting; 195 private Intent mResultDataForTesting; 196 private OnScreenHint mStorageHint; 197 private long mStorageSpaceBytes = Storage.LOW_STORAGE_THRESHOLD_BYTES; 198 private boolean mAutoRotateScreen; 199 private boolean mSecureCamera; 200 private int mLastRawOrientation; 201 private OrientationManagerImpl mOrientationManager; 202 private LocationManager mLocationManager; 203 private Handler mMainHandler; 204 private PanoramaViewHelper mPanoramaViewHelper; 205 private CameraPreviewData mCameraPreviewData; 206 private ActionBar mActionBar; 207 private OnActionBarVisibilityListener mOnActionBarVisibilityListener = null; 208 private Menu mActionBarMenu; 209 private ViewGroup mUndoDeletionBar; 210 private boolean mIsUndoingDeletion = false; 211 212 private final Uri[] mNfcPushUris = new Uri[1]; 213 214 private ShareActionProvider mStandardShareActionProvider; 215 private Intent mStandardShareIntent; 216 private ShareActionProvider mPanoramaShareActionProvider; 217 private Intent mPanoramaShareIntent; 218 private LocalMediaObserver mLocalImagesObserver; 219 private LocalMediaObserver mLocalVideosObserver; 220 221 private boolean mPendingDeletion = false; 222 223 private Intent mVideoShareIntent; 224 private Intent mImageShareIntent; 225 226 private CameraController mCameraController; 227 private boolean mPaused; 228 private CameraAppUI mCameraAppUI; 229 230 private MediaSaver mMediaSaver; 231 232 private FeedbackHelper mFeedbackHelper; 233 234 // close activity when screen turns off 235 private final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() { 236 @Override 237 public void onReceive(Context context, Intent intent) { 238 finish(); 239 } 240 }; 241 242 private static BroadcastReceiver sScreenOffReceiver; 243 244 /** 245 * Whether the screen is kept turned on. 246 */ 247 private boolean mKeepScreenOn; 248 private int mLastLayoutOrientation; 249 250 @Override 251 public void onCameraOpened(CameraManager.CameraProxy camera) { 252 if (!mModuleManager.getModuleAgent(mCurrentModeIndex).requestAppForCamera()) { 253 // We shouldn't be here. Just close the camera and leave. 254 camera.release(false); 255 throw new IllegalStateException("Camera opened but the module shouldn't be " + 256 "requesting"); 257 } 258 if (mCurrentModule != null) { 259 SettingsCapabilities capabilities = 260 SettingsController.getSettingsCapabilities(camera); 261 mSettingsManager.changeCamera(camera.getCameraId(), capabilities); 262 mCurrentModule.onCameraAvailable(camera); 263 } 264 } 265 266 @Override 267 public void onCameraDisabled(int cameraId) { 268 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, UsageStatistics.ACTION_OPEN_FAIL, 269 "security"); 270 271 CameraUtil.showErrorAndFinish(this, R.string.camera_disabled); 272 } 273 274 @Override 275 public void onDeviceOpenFailure(int cameraId) { 276 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, 277 UsageStatistics.ACTION_OPEN_FAIL, "open"); 278 279 CameraUtil.showErrorAndFinish(this, R.string.cannot_connect_camera); 280 } 281 282 @Override 283 public void onReconnectionFailure(CameraManager mgr) { 284 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, 285 UsageStatistics.ACTION_OPEN_FAIL, "reconnect"); 286 287 CameraUtil.showErrorAndFinish(this, R.string.cannot_connect_camera); 288 } 289 290 private class MainHandler extends Handler { 291 public MainHandler(Looper looper) { 292 super(looper); 293 } 294 295 @Override 296 public void handleMessage(Message msg) { 297 switch (msg.what) { 298 case MSG_HIDE_ACTION_BAR: { 299 removeMessages(MSG_HIDE_ACTION_BAR); 300 CameraActivity.this.setSystemBarsVisibility(false); 301 break; 302 } 303 304 case MSG_CLEAR_SCREEN_ON_FLAG: { 305 if (!mPaused) { 306 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 307 } 308 break; 309 } 310 311 default: 312 } 313 } 314 } 315 316 public interface OnActionBarVisibilityListener { 317 public void onActionBarVisibilityChanged(boolean isVisible); 318 } 319 320 public void setOnActionBarVisibilityListener(OnActionBarVisibilityListener listener) { 321 mOnActionBarVisibilityListener = listener; 322 } 323 324 private String fileNameFromDataID(int dataID) { 325 final LocalData localData = mDataAdapter.getLocalData(dataID); 326 327 File localFile = new File(localData.getPath()); 328 return localFile.getName(); 329 } 330 331 private final FilmstripListener mFilmStripListener = 332 new FilmstripListener() { 333 @Override 334 public void onDataPromoted(int dataID) { 335 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, 336 UsageStatistics.ACTION_DELETE, "promoted", 0, 337 UsageStatistics.hashFileName(fileNameFromDataID(dataID))); 338 339 removeData(dataID); 340 } 341 342 @Override 343 public void onDataDemoted(int dataID) { 344 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, 345 UsageStatistics.ACTION_DELETE, "demoted", 0, 346 UsageStatistics.hashFileName(fileNameFromDataID(dataID))); 347 348 removeData(dataID); 349 } 350 351 @Override 352 public void onDataFullScreenChange(int dataID, boolean full) { 353 boolean isCameraID = isCameraPreview(dataID); 354 if (!isCameraID) { 355 if (!full) { 356 // Always show action bar in filmstrip mode 357 CameraActivity.this.setSystemBarsVisibility(true, false); 358 } else if (mActionBar.isShowing()) { 359 // Hide action bar after time out in full screen mode 360 mMainHandler.sendEmptyMessageDelayed(MSG_HIDE_ACTION_BAR, 361 SHOW_ACTION_BAR_TIMEOUT_MS); 362 } 363 } 364 } 365 366 /** 367 * Check if the local data corresponding to dataID is the camera 368 * preview. 369 * 370 * @param dataID the ID of the local data 371 * @return true if the local data is not null and it is the 372 * camera preview. 373 */ 374 private boolean isCameraPreview(int dataID) { 375 LocalData localData = mDataAdapter.getLocalData(dataID); 376 if (localData == null) { 377 Log.w(TAG, "Current data ID not found."); 378 return false; 379 } 380 return localData.getLocalDataType() == LocalData.LOCAL_CAMERA_PREVIEW; 381 } 382 383 @Override 384 public void onDataReloaded() { 385 setPreviewControlsVisibility(true); 386 CameraActivity.this.setSystemBarsVisibility(false); 387 } 388 389 @Override 390 public void onCurrentDataCentered(int dataID) { 391 if (dataID != 0 && !mFilmstripController.isCameraPreview()) { 392 // For now, We ignore all items that are not the camera preview. 393 return; 394 } 395 396 if (!arePreviewControlsVisible()) { 397 setPreviewControlsVisibility(true); 398 CameraActivity.this.setSystemBarsVisibility(false); 399 } 400 } 401 402 @Override 403 public void onCurrentDataOffCentered(int dataID) { 404 if (dataID != 0 && !mFilmstripController.isCameraPreview()) { 405 // For now, We ignore all items that are not the camera preview. 406 return; 407 } 408 409 if (arePreviewControlsVisible()) { 410 setPreviewControlsVisibility(false); 411 } 412 } 413 414 @Override 415 public void onDataFocusChanged(final int dataID, final boolean focused) { 416 // Delay hiding action bar if there is any user interaction 417 if (mMainHandler.hasMessages(MSG_HIDE_ACTION_BAR)) { 418 mMainHandler.removeMessages(MSG_HIDE_ACTION_BAR); 419 mMainHandler.sendEmptyMessageDelayed(MSG_HIDE_ACTION_BAR, 420 SHOW_ACTION_BAR_TIMEOUT_MS); 421 } 422 // TODO: This callback is UI event callback, should always 423 // happen on UI thread. Find the reason for this 424 // runOnUiThread() and fix it. 425 runOnUiThread(new Runnable() { 426 @Override 427 public void run() { 428 LocalData currentData = mDataAdapter.getLocalData(dataID); 429 if (currentData == null) { 430 Log.w(TAG, "Current data ID not found."); 431 hidePanoStitchingProgress(); 432 return; 433 } 434 boolean isCameraID = currentData.getLocalDataType() == 435 LocalData.LOCAL_CAMERA_PREVIEW; 436 if (!focused) { 437 if (isCameraID) { 438 mCurrentModule.onPreviewFocusChanged(false); 439 CameraActivity.this.setSystemBarsVisibility(true); 440 } 441 hidePanoStitchingProgress(); 442 } else { 443 if (isCameraID) { 444 // Don't show the action bar in Camera 445 // preview. 446 CameraActivity.this.setSystemBarsVisibility(false); 447 448 if (mPendingDeletion) { 449 performDeletion(); 450 } 451 } else { 452 updateActionBarMenu(dataID); 453 } 454 455 Uri contentUri = currentData.getContentUri(); 456 if (contentUri == null) { 457 hidePanoStitchingProgress(); 458 return; 459 } 460 int panoStitchingProgress = mPanoramaManager.getTaskProgress(contentUri); 461 if (panoStitchingProgress < 0) { 462 hidePanoStitchingProgress(); 463 return; 464 } 465 showPanoStitchingProgress(); 466 updateStitchingProgress(panoStitchingProgress); 467 } 468 } 469 }); 470 } 471 472 @Override 473 public void onToggleSystemDecorsVisibility(int dataID) { 474 // If action bar is showing, hide it immediately, otherwise 475 // show action bar and hide it later 476 if (mActionBar.isShowing()) { 477 CameraActivity.this.setSystemBarsVisibility(false); 478 } else { 479 // Don't show the action bar if that is the camera preview. 480 boolean isCameraID = isCameraPreview(dataID); 481 if (!isCameraID) { 482 CameraActivity.this.setSystemBarsVisibility(true, true); 483 } 484 } 485 } 486 487 @Override 488 public void setSystemDecorsVisibility(boolean visible) { 489 CameraActivity.this.setSystemBarsVisibility(visible); 490 } 491 }; 492 493 public void gotoGallery() { 494 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, UsageStatistics.ACTION_FILMSTRIP, 495 "thumbnailTap"); 496 497 mFilmstripController.goToNextItem(); 498 } 499 500 /** 501 * If {@param visible} is false, this hides the action bar and switches the system UI 502 * to lights-out mode. 503 */ 504 // TODO: This should not be called outside of the activity. 505 public void setSystemBarsVisibility(boolean visible) { 506 setSystemBarsVisibility(visible, false); 507 } 508 509 /** 510 * If {@param visible} is false, this hides the action bar and switches the 511 * system UI to lights-out mode. If {@param hideLater} is true, a delayed message 512 * will be sent after a timeout to hide the action bar. 513 */ 514 private void setSystemBarsVisibility(boolean visible, boolean hideLater) { 515 mMainHandler.removeMessages(MSG_HIDE_ACTION_BAR); 516 517 int currentSystemUIVisibility = mAboveFilmstripControlLayout.getSystemUiVisibility(); 518 int newSystemUIVisibility = (visible ? View.SYSTEM_UI_FLAG_VISIBLE : 519 View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN); 520 if (newSystemUIVisibility != currentSystemUIVisibility) { 521 mAboveFilmstripControlLayout.setSystemUiVisibility(newSystemUIVisibility); 522 } 523 524 boolean currentActionBarVisibility = mActionBar.isShowing(); 525 if (visible != currentActionBarVisibility) { 526 if (visible) { 527 mActionBar.show(); 528 } else { 529 mActionBar.hide(); 530 } 531 if (mOnActionBarVisibilityListener != null) { 532 mOnActionBarVisibilityListener.onActionBarVisibilityChanged(visible); 533 } 534 } 535 536 // Now delay hiding the bars 537 if (visible && hideLater) { 538 mMainHandler.sendEmptyMessageDelayed(MSG_HIDE_ACTION_BAR, SHOW_ACTION_BAR_TIMEOUT_MS); 539 } 540 } 541 542 private void hidePanoStitchingProgress() { 543 mPanoStitchingPanel.setVisibility(View.GONE); 544 } 545 546 private void showPanoStitchingProgress() { 547 mPanoStitchingPanel.setVisibility(View.VISIBLE); 548 } 549 550 private void updateStitchingProgress(int progress) { 551 mBottomProgress.setProgress(progress); 552 } 553 554 @TargetApi(Build.VERSION_CODES.JELLY_BEAN) 555 private void setupNfcBeamPush() { 556 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(CameraActivity.this); 557 if (adapter == null) { 558 return; 559 } 560 561 if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS) { 562 // Disable beaming 563 adapter.setNdefPushMessage(null, CameraActivity.this); 564 return; 565 } 566 567 adapter.setBeamPushUris(null, CameraActivity.this); 568 adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() { 569 @Override 570 public Uri[] createBeamUris(NfcEvent event) { 571 return mNfcPushUris; 572 } 573 }, CameraActivity.this); 574 } 575 576 private void setNfcBeamPushUri(Uri uri) { 577 mNfcPushUris[0] = uri; 578 } 579 580 private void setStandardShareIntent(Uri contentUri, String mimeType) { 581 mStandardShareIntent = getShareIntentFromType(mimeType); 582 if (mStandardShareIntent != null) { 583 mStandardShareIntent.putExtra(Intent.EXTRA_STREAM, contentUri); 584 mStandardShareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 585 if (mStandardShareActionProvider != null) { 586 mStandardShareActionProvider.setShareIntent(mStandardShareIntent); 587 } 588 } 589 } 590 591 /** 592 * Get the share intent according to the mimeType 593 * 594 * @param mimeType The mimeType of current data. 595 * @return the video/image's ShareIntent or null if mimeType is invalid. 596 */ 597 private Intent getShareIntentFromType(String mimeType) { 598 // Lazily create the intent object. 599 if (mimeType.startsWith("video/")) { 600 if (mVideoShareIntent == null) { 601 mVideoShareIntent = new Intent(Intent.ACTION_SEND); 602 mVideoShareIntent.setType("video/*"); 603 } 604 return mVideoShareIntent; 605 } else if (mimeType.startsWith("image/")) { 606 if (mImageShareIntent == null) { 607 mImageShareIntent = new Intent(Intent.ACTION_SEND); 608 mImageShareIntent.setType("image/*"); 609 } 610 return mImageShareIntent; 611 } 612 Log.w(TAG, "unsupported mimeType " + mimeType); 613 return null; 614 } 615 616 private void setPanoramaShareIntent(Uri contentUri) { 617 if (mPanoramaShareIntent == null) { 618 mPanoramaShareIntent = new Intent(Intent.ACTION_SEND); 619 } 620 mPanoramaShareIntent.setType("application/vnd.google.panorama360+jpg"); 621 mPanoramaShareIntent.putExtra(Intent.EXTRA_STREAM, contentUri); 622 if (mPanoramaShareActionProvider != null) { 623 mPanoramaShareActionProvider.setShareIntent(mPanoramaShareIntent); 624 } 625 } 626 627 @Override 628 public void onMenuVisibilityChanged(boolean isVisible) { 629 // If menu is showing, we need to make sure action bar does not go away. 630 mMainHandler.removeMessages(MSG_HIDE_ACTION_BAR); 631 if (!isVisible) { 632 mMainHandler.sendEmptyMessageDelayed(MSG_HIDE_ACTION_BAR, SHOW_ACTION_BAR_TIMEOUT_MS); 633 } 634 } 635 636 @Override 637 public boolean onShareTargetSelected(ShareActionProvider shareActionProvider, Intent intent) { 638 int currentDataId = mFilmstripController.getCurrentId(); 639 if (currentDataId < 0) { 640 return false; 641 } 642 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, UsageStatistics.ACTION_SHARE, 643 intent.getComponent().getPackageName(), 0, 644 UsageStatistics.hashFileName(fileNameFromDataID(currentDataId))); 645 return true; 646 } 647 648 /** 649 * According to the data type, make the menu items for supported operations 650 * visible. 651 * 652 * @param dataID the data ID of the current item. 653 */ 654 private void updateActionBarMenu(int dataID) { 655 LocalData currentData = mDataAdapter.getLocalData(dataID); 656 if (currentData == null) { 657 return; 658 } 659 int type = currentData.getLocalDataType(); 660 661 if (mActionBarMenu == null) { 662 return; 663 } 664 665 int supported = 0; 666 667 switch (type) { 668 case LocalData.LOCAL_IMAGE: 669 supported |= SUPPORT_DELETE | SUPPORT_ROTATE | SUPPORT_INFO 670 | SUPPORT_CROP | SUPPORT_SETAS | SUPPORT_EDIT 671 | SUPPORT_SHARE | SUPPORT_SHOW_ON_MAP; 672 break; 673 case LocalData.LOCAL_VIDEO: 674 supported |= SUPPORT_DELETE | SUPPORT_INFO | SUPPORT_TRIM 675 | SUPPORT_SHARE; 676 break; 677 case LocalData.LOCAL_PHOTO_SPHERE: 678 supported |= SUPPORT_DELETE | SUPPORT_ROTATE | SUPPORT_INFO 679 | SUPPORT_CROP | SUPPORT_SETAS | SUPPORT_EDIT 680 | SUPPORT_SHARE | SUPPORT_SHOW_ON_MAP; 681 break; 682 case LocalData.LOCAL_360_PHOTO_SPHERE: 683 supported |= SUPPORT_DELETE | SUPPORT_ROTATE | SUPPORT_INFO 684 | SUPPORT_CROP | SUPPORT_SETAS | SUPPORT_EDIT 685 | SUPPORT_SHARE | SUPPORT_SHARE_PANORAMA360 686 | SUPPORT_SHOW_ON_MAP; 687 break; 688 default: 689 break; 690 } 691 692 // In secure camera mode, we only support delete operation. 693 if (isSecureCamera()) { 694 supported &= SUPPORT_DELETE; 695 } 696 697 setMenuItemVisible(mActionBarMenu, R.id.action_delete, 698 (supported & SUPPORT_DELETE) != 0); 699 setMenuItemVisible(mActionBarMenu, R.id.action_rotate_ccw, 700 (supported & SUPPORT_ROTATE) != 0); 701 setMenuItemVisible(mActionBarMenu, R.id.action_rotate_cw, 702 (supported & SUPPORT_ROTATE) != 0); 703 setMenuItemVisible(mActionBarMenu, R.id.action_details, 704 (supported & SUPPORT_INFO) != 0); 705 setMenuItemVisible(mActionBarMenu, R.id.action_crop, 706 (supported & SUPPORT_CROP) != 0); 707 setMenuItemVisible(mActionBarMenu, R.id.action_setas, 708 (supported & SUPPORT_SETAS) != 0); 709 setMenuItemVisible(mActionBarMenu, R.id.action_edit, 710 (supported & SUPPORT_EDIT) != 0); 711 setMenuItemVisible(mActionBarMenu, R.id.action_trim, 712 (supported & SUPPORT_TRIM) != 0); 713 714 boolean standardShare = (supported & SUPPORT_SHARE) != 0; 715 boolean panoramaShare = (supported & SUPPORT_SHARE_PANORAMA360) != 0; 716 setMenuItemVisible(mActionBarMenu, R.id.action_share, standardShare); 717 setMenuItemVisible(mActionBarMenu, R.id.action_share_panorama, panoramaShare); 718 719 if (panoramaShare) { 720 // For 360 PhotoSphere, relegate standard share to the overflow menu 721 MenuItem item = mActionBarMenu.findItem(R.id.action_share); 722 if (item != null) { 723 item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); 724 item.setTitle(getResources().getString(R.string.share_as_photo)); 725 } 726 // And, promote "share as panorama" to action bar 727 item = mActionBarMenu.findItem(R.id.action_share_panorama); 728 if (item != null) { 729 item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); 730 } 731 setPanoramaShareIntent(currentData.getContentUri()); 732 } 733 if (standardShare) { 734 if (!panoramaShare) { 735 MenuItem item = mActionBarMenu.findItem(R.id.action_share); 736 if (item != null) { 737 item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); 738 item.setTitle(getResources().getString(R.string.share)); 739 } 740 } 741 setStandardShareIntent(currentData.getContentUri(), currentData.getMimeType()); 742 setNfcBeamPushUri(currentData.getContentUri()); 743 } 744 745 boolean itemHasLocation = currentData.getLatLong() != null; 746 setMenuItemVisible(mActionBarMenu, R.id.action_show_on_map, 747 itemHasLocation && (supported & SUPPORT_SHOW_ON_MAP) != 0); 748 } 749 750 private void setMenuItemVisible(Menu menu, int itemId, boolean visible) { 751 MenuItem item = menu.findItem(itemId); 752 if (item != null) { 753 item.setVisible(visible); 754 } 755 } 756 757 private final ImageTaskManager.TaskListener mPlaceholderListener = 758 new ImageTaskManager.TaskListener() { 759 760 @Override 761 public void onTaskQueued(String filePath, final Uri imageUri) { 762 mMainHandler.post(new Runnable() { 763 @Override 764 public void run() { 765 notifyNewMedia(imageUri); 766 int dataID = mDataAdapter.findDataByContentUri(imageUri); 767 if (dataID != -1) { 768 LocalData d = mDataAdapter.getLocalData(dataID); 769 InProgressDataWrapper newData = new InProgressDataWrapper(d, true); 770 mDataAdapter.updateData(dataID, newData); 771 } 772 } 773 }); 774 } 775 776 @Override 777 public void onTaskDone(String filePath, final Uri imageUri) { 778 mMainHandler.post(new Runnable() { 779 @Override 780 public void run() { 781 mDataAdapter.refresh(getContentResolver(), imageUri); 782 } 783 }); 784 } 785 786 @Override 787 public void onTaskProgress(String filePath, Uri imageUri, int progress) { 788 // Do nothing 789 } 790 }; 791 792 private final ImageTaskManager.TaskListener mStitchingListener = 793 new ImageTaskManager.TaskListener() { 794 @Override 795 public void onTaskQueued(String filePath, final Uri imageUri) { 796 mMainHandler.post(new Runnable() { 797 @Override 798 public void run() { 799 notifyNewMedia(imageUri); 800 int dataID = mDataAdapter.findDataByContentUri(imageUri); 801 if (dataID != -1) { 802 // Don't allow special UI actions (swipe to 803 // delete, for example) on in-progress data. 804 LocalData d = mDataAdapter.getLocalData(dataID); 805 InProgressDataWrapper newData = new InProgressDataWrapper(d); 806 mDataAdapter.updateData(dataID, newData); 807 } 808 } 809 }); 810 } 811 812 @Override 813 public void onTaskDone(String filePath, final Uri imageUri) { 814 Log.v(TAG, "onTaskDone:" + filePath); 815 mMainHandler.post(new Runnable() { 816 @Override 817 public void run() { 818 int doneID = mDataAdapter.findDataByContentUri(imageUri); 819 int currentDataId = mFilmstripController.getCurrentId(); 820 821 if (currentDataId == doneID) { 822 hidePanoStitchingProgress(); 823 updateStitchingProgress(0); 824 } 825 826 mDataAdapter.refresh(getContentResolver(), imageUri); 827 } 828 }); 829 } 830 831 @Override 832 public void onTaskProgress( 833 String filePath, final Uri imageUri, final int progress) { 834 mMainHandler.post(new Runnable() { 835 @Override 836 public void run() { 837 int currentDataId = mFilmstripController.getCurrentId(); 838 if (currentDataId == -1) { 839 return; 840 } 841 if (imageUri.equals( 842 mDataAdapter.getLocalData(currentDataId).getContentUri())) { 843 updateStitchingProgress(progress); 844 } 845 } 846 }); 847 } 848 }; 849 850 @Override 851 public Context getAndroidContext() { 852 return this; 853 } 854 855 @Override 856 public int getCurrentModuleIndex() { 857 return mCurrentModeIndex; 858 } 859 860 @Override 861 public SurfaceTexture getPreviewBuffer() { 862 // TODO: implement this 863 return null; 864 } 865 866 @Override 867 public FrameLayout getModuleLayoutRoot() { 868 return mCameraModuleRootView; 869 } 870 871 @Override 872 public void setShutterEventsListener(ShutterEventsListener listener) { 873 // TODO: implement this 874 } 875 876 @Override 877 public void setShutterEnabled(boolean enabled) { 878 // TODO: implement this 879 } 880 881 @Override 882 public boolean isShutterEnabled() { 883 // TODO: implement this 884 return false; 885 } 886 887 @Override 888 public void startPreCaptureAnimation() { 889 // TODO: implement this 890 } 891 892 @Override 893 public void cancelPreCaptureAnimation() { 894 // TODO: implement this 895 } 896 897 @Override 898 public void startPostCaptureAnimation() { 899 // TODO: implement this 900 } 901 902 @Override 903 public void startPostCaptureAnimation(Bitmap thumbnail) { 904 // TODO: implement this 905 } 906 907 @Override 908 public void cancelPostCaptureAnimation() { 909 // TODO: implement this 910 } 911 912 @Override 913 public OrientationManager getOrientationManager() { 914 return mOrientationManager; 915 } 916 917 @Override 918 public LocationManager getLocationManager() { 919 return mLocationManager; 920 } 921 922 @Override 923 public void lockOrientation() { 924 mOrientationManager.lockOrientation(); 925 } 926 927 @Override 928 public void unlockOrientation() { 929 mOrientationManager.unlockOrientation(); 930 } 931 932 @Override 933 public void notifyNewMedia(Uri uri) { 934 ContentResolver cr = getContentResolver(); 935 String mimeType = cr.getType(uri); 936 if (mimeType.startsWith("video/")) { 937 sendBroadcast(new Intent(CameraUtil.ACTION_NEW_VIDEO, uri)); 938 mDataAdapter.addNewVideo(cr, uri); 939 } else if (mimeType.startsWith("image/")) { 940 CameraUtil.broadcastNewPicture(this, uri); 941 mDataAdapter.addNewPhoto(cr, uri); 942 } else if (mimeType.startsWith("application/stitching-preview")) { 943 mDataAdapter.addNewPhoto(cr, uri); 944 } else if (mimeType.startsWith(PlaceholderManager.PLACEHOLDER_MIME_TYPE)) { 945 mDataAdapter.addNewPhoto(cr, uri); 946 } else { 947 android.util.Log.w(TAG, "Unknown new media with MIME type:" 948 + mimeType + ", uri:" + uri); 949 } 950 } 951 952 @Override 953 public void enableKeepScreenOn(boolean enabled) { 954 if (mPaused) { 955 return; 956 } 957 958 mKeepScreenOn = enabled; 959 if (mKeepScreenOn) { 960 mMainHandler.removeMessages(MSG_CLEAR_SCREEN_ON_FLAG); 961 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 962 } else { 963 keepScreenOnForAWhile(); 964 } 965 } 966 967 @Override 968 public CameraProvider getCameraProvider() { 969 return mCameraController; 970 } 971 972 private void removeData(int dataID) { 973 mDataAdapter.removeData(CameraActivity.this, dataID); 974 if (mDataAdapter.getTotalNumber() > 1) { 975 showUndoDeletionBar(); 976 } else { 977 // If camera preview is the only view left in filmstrip, 978 // no need to show undo bar. 979 mPendingDeletion = true; 980 performDeletion(); 981 } 982 } 983 984 985 @Override 986 public boolean onCreateOptionsMenu(Menu menu) { 987 // Inflate the menu items for use in the action bar 988 MenuInflater inflater = getMenuInflater(); 989 inflater.inflate(R.menu.operations, menu); 990 mActionBarMenu = menu; 991 992 // Configure the standard share action provider 993 MenuItem item = menu.findItem(R.id.action_share); 994 mStandardShareActionProvider = (ShareActionProvider) item.getActionProvider(); 995 mStandardShareActionProvider.setShareHistoryFileName("standard_share_history.xml"); 996 if (mStandardShareIntent != null) { 997 mStandardShareActionProvider.setShareIntent(mStandardShareIntent); 998 } 999 1000 // Configure the panorama share action provider 1001 item = menu.findItem(R.id.action_share_panorama); 1002 mPanoramaShareActionProvider = (ShareActionProvider) item.getActionProvider(); 1003 mPanoramaShareActionProvider.setShareHistoryFileName("panorama_share_history.xml"); 1004 if (mPanoramaShareIntent != null) { 1005 mPanoramaShareActionProvider.setShareIntent(mPanoramaShareIntent); 1006 } 1007 1008 mStandardShareActionProvider.setOnShareTargetSelectedListener(this); 1009 mPanoramaShareActionProvider.setOnShareTargetSelectedListener(this); 1010 1011 return super.onCreateOptionsMenu(menu); 1012 } 1013 1014 @Override 1015 public boolean onOptionsItemSelected(MenuItem item) { 1016 int currentDataId = mFilmstripController.getCurrentId(); 1017 if (currentDataId < 0) { 1018 return false; 1019 } 1020 final LocalData localData = mDataAdapter.getLocalData(currentDataId); 1021 1022 // Handle presses on the action bar items 1023 switch (item.getItemId()) { 1024 case android.R.id.home: 1025 // ActionBar's Up/Home button was clicked 1026 try { 1027 startActivity(IntentHelper.getGalleryIntent(this)); 1028 return true; 1029 } catch (ActivityNotFoundException e) { 1030 Log.w(TAG, "Failed to launch gallery activity, closing"); 1031 finish(); 1032 } 1033 case R.id.action_delete: 1034 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, 1035 UsageStatistics.ACTION_DELETE, null, 0, 1036 UsageStatistics.hashFileName(fileNameFromDataID(currentDataId))); 1037 removeData(currentDataId); 1038 return true; 1039 case R.id.action_edit: 1040 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, 1041 UsageStatistics.ACTION_EDIT, null, 0, 1042 UsageStatistics.hashFileName(fileNameFromDataID(currentDataId))); 1043 launchEditor(localData); 1044 return true; 1045 case R.id.action_trim: { 1046 // This is going to be handled by the Gallery app. 1047 Intent intent = new Intent(ACTION_TRIM_VIDEO); 1048 LocalData currentData = mDataAdapter.getLocalData(mFilmstripController.getCurrentId()); 1049 intent.setData(currentData.getContentUri()); 1050 // We need the file path to wrap this into a RandomAccessFile. 1051 intent.putExtra(MEDIA_ITEM_PATH, currentData.getPath()); 1052 startActivityForResult(intent, REQ_CODE_DONT_SWITCH_TO_PREVIEW); 1053 return true; 1054 } 1055 case R.id.action_rotate_ccw: 1056 localData.rotate90Degrees(this, mDataAdapter, currentDataId, false); 1057 return true; 1058 case R.id.action_rotate_cw: 1059 localData.rotate90Degrees(this, mDataAdapter, currentDataId, true); 1060 return true; 1061 case R.id.action_crop: { 1062 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, 1063 UsageStatistics.ACTION_CROP, null, 0, 1064 UsageStatistics.hashFileName(fileNameFromDataID(currentDataId))); 1065 Intent intent = new Intent(CropActivity.CROP_ACTION); 1066 intent.setClass(this, CropActivity.class); 1067 intent.setDataAndType(localData.getContentUri(), localData.getMimeType()) 1068 .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 1069 startActivityForResult(intent, REQ_CODE_DONT_SWITCH_TO_PREVIEW); 1070 return true; 1071 } 1072 case R.id.action_setas: { 1073 Intent intent = new Intent(Intent.ACTION_ATTACH_DATA) 1074 .setDataAndType(localData.getContentUri(), 1075 localData.getMimeType()) 1076 .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 1077 intent.putExtra("mimeType", intent.getType()); 1078 startActivityForResult(Intent.createChooser( 1079 intent, getString(R.string.set_as)), REQ_CODE_DONT_SWITCH_TO_PREVIEW); 1080 return true; 1081 } 1082 case R.id.action_details: 1083 (new AsyncTask<Void, Void, MediaDetails>() { 1084 @Override 1085 protected MediaDetails doInBackground(Void... params) { 1086 return localData.getMediaDetails(CameraActivity.this); 1087 } 1088 1089 @Override 1090 protected void onPostExecute(MediaDetails mediaDetails) { 1091 if (mediaDetails != null) { 1092 DetailsDialog.create(CameraActivity.this, mediaDetails).show(); 1093 } 1094 } 1095 }).execute(); 1096 return true; 1097 case R.id.action_show_on_map: 1098 double[] latLong = localData.getLatLong(); 1099 if (latLong != null) { 1100 CameraUtil.showOnMap(this, latLong); 1101 } 1102 return true; 1103 default: 1104 return super.onOptionsItemSelected(item); 1105 } 1106 } 1107 1108 private boolean isCaptureIntent() { 1109 if (MediaStore.ACTION_VIDEO_CAPTURE.equals(getIntent().getAction()) 1110 || MediaStore.ACTION_IMAGE_CAPTURE.equals(getIntent().getAction()) 1111 || MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(getIntent().getAction())) { 1112 return true; 1113 } else { 1114 return false; 1115 } 1116 } 1117 1118 @Override 1119 public void onCreate(Bundle state) { 1120 super.onCreate(state); 1121 GcamHelper.init(getContentResolver()); 1122 1123 getWindow().requestFeature(Window.FEATURE_ACTION_BAR); 1124 setContentView(R.layout.activity_main); 1125 mActionBar = getActionBar(); 1126 mActionBar.addOnMenuVisibilityListener(this); 1127 mMainHandler = new MainHandler(getMainLooper()); 1128 mCameraController = 1129 new CameraController(this, this, mMainHandler, 1130 CameraManagerFactory.getAndroidCameraManager()); 1131 ComboPreferences prefs = new ComboPreferences(getAndroidContext()); 1132 1133 mSettingsManager = new SettingsManager(this, null, mCameraController.getNumberOfCameras()); 1134 // Remove this after we get rid of ComboPreferences. 1135 int cameraId = Integer.parseInt(mSettingsManager.get(SettingsManager.SETTING_CAMERA_ID)); 1136 prefs.setLocalId(this, cameraId); 1137 CameraSettings.upgradeGlobalPreferences(prefs, mCameraController.getNumberOfCameras()); 1138 // TODO: Try to move all the resources allocation to happen as soon as 1139 // possible so we can call module.init() at the earliest time. 1140 mModuleManager = new ModuleManagerImpl(); 1141 ModulesInfo.setupModules(this, mModuleManager); 1142 1143 mModeListView = (ModeListView) findViewById(R.id.mode_list_layout); 1144 if (ApiHelper.HAS_ROTATION_ANIMATION) { 1145 setRotationAnimation(); 1146 } 1147 1148 // Check if this is in the secure camera mode. 1149 Intent intent = getIntent(); 1150 String action = intent.getAction(); 1151 if (INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action) 1152 || ACTION_IMAGE_CAPTURE_SECURE.equals(action)) { 1153 mSecureCamera = true; 1154 } else { 1155 mSecureCamera = intent.getBooleanExtra(SECURE_CAMERA_EXTRA, false); 1156 } 1157 1158 if (mSecureCamera) { 1159 // Change the window flags so that secure camera can show when locked 1160 Window win = getWindow(); 1161 WindowManager.LayoutParams params = win.getAttributes(); 1162 params.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; 1163 win.setAttributes(params); 1164 1165 // Filter for screen off so that we can finish secure camera activity 1166 // when screen is off. 1167 IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); 1168 registerReceiver(mScreenOffReceiver, filter); 1169 } 1170 mAboveFilmstripControlLayout = 1171 (FrameLayout) findViewById(R.id.camera_above_filmstrip_layout); 1172 mAboveFilmstripControlLayout.setFitsSystemWindows(true); 1173 // Hide action bar first since we are in full screen mode first, and 1174 // switch the system UI to lights-out mode. 1175 this.setSystemBarsVisibility(false); 1176 mPanoramaManager = AppManagerFactory.getInstance(this) 1177 .getPanoramaStitchingManager(); 1178 mPlaceholderManager = AppManagerFactory.getInstance(this) 1179 .getGcamProcessingManager(); 1180 mPanoramaManager.addTaskListener(mStitchingListener); 1181 mPlaceholderManager.addTaskListener(mPlaceholderListener); 1182 LayoutInflater inflater = getLayoutInflater(); 1183 View rootLayout = inflater.inflate(R.layout.camera, null, false); 1184 mCameraModuleRootView = (FrameLayout) rootLayout.findViewById(R.id.camera_app_root); 1185 mPanoStitchingPanel = findViewById(R.id.pano_stitching_progress_panel); 1186 mBottomProgress = (ProgressBar) findViewById(R.id.pano_stitching_progress_bar); 1187 mCameraPreviewData = new CameraPreviewData(rootLayout, 1188 FilmstripImageData.SIZE_FULL, 1189 FilmstripImageData.SIZE_FULL); 1190 // Put a CameraPreviewData at the first position. 1191 mWrappedDataAdapter = new FixedFirstDataAdapter( 1192 new CameraDataAdapter(new ColorDrawable( 1193 getResources().getColor(R.color.photo_placeholder))), 1194 mCameraPreviewData); 1195 mFilmstripController = ((FilmstripView) findViewById(R.id.filmstrip_view)).getController(); 1196 mFilmstripController.setViewGap( 1197 getResources().getDimensionPixelSize(R.dimen.camera_film_strip_gap)); 1198 mPanoramaViewHelper = new PanoramaViewHelper(this); 1199 mPanoramaViewHelper.onCreate(); 1200 mFilmstripController.setPanoramaViewHelper(mPanoramaViewHelper); 1201 // Set up the camera preview first so the preview shows up ASAP. 1202 mFilmstripController.setListener(mFilmStripListener); 1203 1204 // TODO: Remove the 3rd parameter once mCameraModuleRoot is moved out of filmstrip 1205 mCameraAppUI = new CameraAppUI(this, 1206 (MainActivityLayout) findViewById(R.id.activity_root_view), 1207 mCameraModuleRootView, 1208 isSecureCamera(), isCaptureIntent()); 1209 1210 mLocationManager = new LocationManager(this, 1211 new LocationManager.Listener() { 1212 @Override 1213 public void showGpsOnScreenIndicator(boolean hasSignal) { 1214 } 1215 1216 @Override 1217 public void hideGpsOnScreenIndicator() { 1218 } 1219 }); 1220 1221 mSettingsController = new SettingsController(this, mSettingsManager, mLocationManager); 1222 1223 int modeIndex = -1; 1224 if (MediaStore.INTENT_ACTION_VIDEO_CAMERA.equals(getIntent().getAction()) 1225 || MediaStore.ACTION_VIDEO_CAPTURE.equals(getIntent().getAction())) { 1226 modeIndex = ModeListView.MODE_VIDEO; 1227 } else if (MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA.equals(getIntent().getAction()) 1228 || MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(getIntent() 1229 .getAction())) { 1230 modeIndex = ModeListView.MODE_PHOTO; 1231 if (mSettingsManager.getInt(SettingsManager.SETTING_STARTUP_MODULE_INDEX) 1232 == ModeListView.MODE_GCAM && GcamHelper.hasGcamCapture()) { 1233 modeIndex = ModeListView.MODE_GCAM; 1234 } 1235 } else if (MediaStore.ACTION_IMAGE_CAPTURE.equals(getIntent().getAction()) 1236 || MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(getIntent().getAction())) { 1237 modeIndex = ModeListView.MODE_PHOTO; 1238 } else { 1239 // If the activity has not been started using an explicit intent, 1240 // read the module index from the last time the user changed modes 1241 modeIndex = mSettingsManager.getInt(SettingsManager.SETTING_STARTUP_MODULE_INDEX); 1242 if ((modeIndex == ModeListView.MODE_GCAM && 1243 !GcamHelper.hasGcamCapture()) || modeIndex < 0) { 1244 modeIndex = ModeListView.MODE_PHOTO; 1245 } 1246 } 1247 1248 mOrientationManager = new OrientationManagerImpl(this); 1249 mOrientationManager.addOnOrientationChangeListener(mMainHandler, this); 1250 1251 setModuleFromModeIndex(modeIndex); 1252 1253 // TODO: Remove this when refactor is done. 1254 if (modeIndex == ModulesInfo.MODULE_PHOTO || 1255 modeIndex == ModulesInfo.MODULE_VIDEO) { 1256 mCameraAppUI.prepareModuleUI(); 1257 } 1258 mCurrentModule.init(this, isSecureCamera(), isCaptureIntent()); 1259 1260 if (!mSecureCamera) { 1261 mDataAdapter = mWrappedDataAdapter; 1262 mFilmstripController.setDataAdapter(mDataAdapter); 1263 if (!isCaptureIntent()) { 1264 mDataAdapter.requestLoad(getContentResolver()); 1265 } 1266 } else { 1267 // Put a lock placeholder as the last image by setting its date to 1268 // 0. 1269 ImageView v = (ImageView) getLayoutInflater().inflate( 1270 R.layout.secure_album_placeholder, null); 1271 v.setOnClickListener(new View.OnClickListener() { 1272 @Override 1273 public void onClick(View view) { 1274 try { 1275 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, 1276 UsageStatistics.ACTION_GALLERY, null); 1277 startActivity(IntentHelper.getGalleryIntent(CameraActivity.this)); 1278 } catch (ActivityNotFoundException e) { 1279 Log.w(TAG, "Failed to launch gallery activity, closing"); 1280 } 1281 finish(); 1282 } 1283 }); 1284 mDataAdapter = new FixedLastDataAdapter( 1285 mWrappedDataAdapter, 1286 new SimpleViewData( 1287 v, 1288 v.getDrawable().getIntrinsicWidth(), 1289 v.getDrawable().getIntrinsicHeight(), 1290 0, 0)); 1291 // Flush out all the original data. 1292 mDataAdapter.flush(); 1293 mFilmstripController.setDataAdapter(mDataAdapter); 1294 } 1295 1296 setupNfcBeamPush(); 1297 1298 mLocalImagesObserver = new LocalMediaObserver(); 1299 mLocalVideosObserver = new LocalMediaObserver(); 1300 1301 getContentResolver().registerContentObserver( 1302 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true, 1303 mLocalImagesObserver); 1304 getContentResolver().registerContentObserver( 1305 MediaStore.Video.Media.EXTERNAL_CONTENT_URI, true, 1306 mLocalVideosObserver); 1307 if (FeedbackHelper.feedbackAvailable()) { 1308 mFeedbackHelper = new FeedbackHelper(this); 1309 } 1310 } 1311 1312 private void setRotationAnimation() { 1313 int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE; 1314 rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE; 1315 Window win = getWindow(); 1316 WindowManager.LayoutParams winParams = win.getAttributes(); 1317 winParams.rotationAnimation = rotationAnimation; 1318 win.setAttributes(winParams); 1319 } 1320 1321 @Override 1322 public void onUserInteraction() { 1323 super.onUserInteraction(); 1324 if (!isFinishing()) { 1325 keepScreenOnForAWhile(); 1326 } 1327 } 1328 1329 @Override 1330 public boolean dispatchTouchEvent(MotionEvent ev) { 1331 boolean result = super.dispatchTouchEvent(ev); 1332 if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) { 1333 // Real deletion is postponed until the next user interaction after 1334 // the gesture that triggers deletion. Until real deletion is performed, 1335 // users can click the undo button to bring back the image that they 1336 // chose to delete. 1337 if (mPendingDeletion && !mIsUndoingDeletion) { 1338 performDeletion(); 1339 } 1340 } 1341 return result; 1342 } 1343 1344 @Override 1345 public void onPause() { 1346 mPaused = true; 1347 1348 // Delete photos that are pending deletion 1349 performDeletion(); 1350 // TODO: call mCurrentModule.pause() instead after all the modules 1351 // support pause(). 1352 mCurrentModule.pause(); 1353 mOrientationManager.pause(); 1354 // Close the camera and wait for the operation done. 1355 mCameraController.closeCamera(); 1356 1357 mLocalImagesObserver.setActivityPaused(true); 1358 mLocalVideosObserver.setActivityPaused(true); 1359 resetScreenOn(); 1360 super.onPause(); 1361 } 1362 1363 @Override 1364 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 1365 if (requestCode == REQ_CODE_DONT_SWITCH_TO_PREVIEW) { 1366 mResetToPreviewOnResume = false; 1367 } else { 1368 super.onActivityResult(requestCode, resultCode, data); 1369 } 1370 } 1371 1372 @Override 1373 public void onResume() { 1374 mPaused = false; 1375 1376 mLastLayoutOrientation = getResources().getConfiguration().orientation; 1377 1378 // TODO: Handle this in OrientationManager. 1379 // Auto-rotate off 1380 if (Settings.System.getInt(getContentResolver(), 1381 Settings.System.ACCELEROMETER_ROTATION, 0) == 0) { 1382 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); 1383 mAutoRotateScreen = false; 1384 } else { 1385 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); 1386 mAutoRotateScreen = true; 1387 } 1388 1389 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, 1390 UsageStatistics.ACTION_FOREGROUNDED, this.getClass().getSimpleName()); 1391 1392 mOrientationManager.resume(); 1393 super.onResume(); 1394 mCurrentModule.resume(); 1395 1396 setSwipingEnabled(true); 1397 1398 if (mResetToPreviewOnResume) { 1399 // Go to the preview on resume. 1400 mFilmstripController.goToFirstItem(); 1401 } 1402 // Default is showing the preview, unless disabled by explicitly 1403 // starting an activity we want to return from to the filmstrip rather 1404 // than the preview. 1405 mResetToPreviewOnResume = true; 1406 1407 if (mLocalVideosObserver.isMediaDataChangedDuringPause() 1408 || mLocalImagesObserver.isMediaDataChangedDuringPause()) { 1409 if (!mSecureCamera) { 1410 // If it's secure camera, requestLoad() should not be called 1411 // as it will load all the data. 1412 mDataAdapter.requestLoad(getContentResolver()); 1413 } 1414 } 1415 mLocalImagesObserver.setActivityPaused(false); 1416 mLocalVideosObserver.setActivityPaused(false); 1417 1418 keepScreenOnForAWhile(); 1419 1420 mModeListView.startAccordionAnimation(); 1421 } 1422 1423 @Override 1424 public void onStart() { 1425 super.onStart(); 1426 mPanoramaViewHelper.onStart(); 1427 } 1428 1429 @Override 1430 protected void onStop() { 1431 mPanoramaViewHelper.onStop(); 1432 if (mFeedbackHelper != null) { 1433 mFeedbackHelper.stopFeedback(); 1434 } 1435 1436 CameraManagerFactory.recycle(); 1437 super.onStop(); 1438 } 1439 1440 @Override 1441 public void onDestroy() { 1442 if (mSecureCamera) { 1443 unregisterReceiver(mScreenOffReceiver); 1444 } 1445 getContentResolver().unregisterContentObserver(mLocalImagesObserver); 1446 getContentResolver().unregisterContentObserver(mLocalVideosObserver); 1447 super.onDestroy(); 1448 } 1449 1450 @Override 1451 public void onConfigurationChanged(Configuration config) { 1452 super.onConfigurationChanged(config); 1453 if (mLastLayoutOrientation != config.orientation) { 1454 mLastLayoutOrientation = config.orientation; 1455 mCurrentModule.onLayoutOrientationChanged(mLastLayoutOrientation); 1456 } 1457 } 1458 1459 @Override 1460 public boolean onKeyDown(int keyCode, KeyEvent event) { 1461 if (mFilmstripController.inCameraFullscreen()) { 1462 if (mCurrentModule.onKeyDown(keyCode, event)) { 1463 return true; 1464 } 1465 // Prevent software keyboard or voice search from showing up. 1466 if (keyCode == KeyEvent.KEYCODE_SEARCH 1467 || keyCode == KeyEvent.KEYCODE_MENU) { 1468 if (event.isLongPress()) { 1469 return true; 1470 } 1471 } 1472 } 1473 1474 return super.onKeyDown(keyCode, event); 1475 } 1476 1477 @Override 1478 public boolean onKeyUp(int keyCode, KeyEvent event) { 1479 if (mFilmstripController.inCameraFullscreen() && mCurrentModule.onKeyUp(keyCode, event)) { 1480 return true; 1481 } 1482 return super.onKeyUp(keyCode, event); 1483 } 1484 1485 @Override 1486 public void onBackPressed() { 1487 if (!mFilmstripController.inCameraFullscreen()) { 1488 mFilmstripController.goToFirstItem(); 1489 } else if (!mCurrentModule.onBackPressed()) { 1490 super.onBackPressed(); 1491 } 1492 } 1493 1494 public boolean isAutoRotateScreen() { 1495 return mAutoRotateScreen; 1496 } 1497 1498 protected void updateStorageSpace() { 1499 mStorageSpaceBytes = Storage.getAvailableSpace(); 1500 } 1501 1502 protected long getStorageSpaceBytes() { 1503 return mStorageSpaceBytes; 1504 } 1505 1506 protected void updateStorageSpaceAndHint() { 1507 updateStorageSpace(); 1508 updateStorageHint(mStorageSpaceBytes); 1509 } 1510 1511 protected void updateStorageHint(long storageSpace) { 1512 String message = null; 1513 if (storageSpace == Storage.UNAVAILABLE) { 1514 message = getString(R.string.no_storage); 1515 } else if (storageSpace == Storage.PREPARING) { 1516 message = getString(R.string.preparing_sd); 1517 } else if (storageSpace == Storage.UNKNOWN_SIZE) { 1518 message = getString(R.string.access_sd_fail); 1519 } else if (storageSpace <= Storage.LOW_STORAGE_THRESHOLD_BYTES) { 1520 message = getString(R.string.spaceIsLow_content); 1521 } 1522 1523 if (message != null) { 1524 if (mStorageHint == null) { 1525 mStorageHint = OnScreenHint.makeText(this, message); 1526 } else { 1527 mStorageHint.setText(message); 1528 } 1529 mStorageHint.show(); 1530 } else if (mStorageHint != null) { 1531 mStorageHint.cancel(); 1532 mStorageHint = null; 1533 } 1534 } 1535 1536 protected void setResultEx(int resultCode) { 1537 mResultCodeForTesting = resultCode; 1538 setResult(resultCode); 1539 } 1540 1541 protected void setResultEx(int resultCode, Intent data) { 1542 mResultCodeForTesting = resultCode; 1543 mResultDataForTesting = data; 1544 setResult(resultCode, data); 1545 } 1546 1547 public int getResultCode() { 1548 return mResultCodeForTesting; 1549 } 1550 1551 public Intent getResultData() { 1552 return mResultDataForTesting; 1553 } 1554 1555 public boolean isSecureCamera() { 1556 return mSecureCamera; 1557 } 1558 1559 @Override 1560 public boolean isPaused() { 1561 return mPaused; 1562 } 1563 1564 @Override 1565 public void onModeSelected(int modeIndex) { 1566 if (mCurrentModeIndex == modeIndex) { 1567 return; 1568 } 1569 1570 if (modeIndex == ModeListView.MODE_SETTING) { 1571 onSettingsSelected(); 1572 return; 1573 } 1574 1575 CameraHolder.instance().keep(); 1576 closeModule(mCurrentModule); 1577 int oldModuleIndex = mCurrentModeIndex; 1578 setModuleFromModeIndex(modeIndex); 1579 1580 // TODO: The following check is temporary for quick switch between video and photo. 1581 // When the refactor is done, similar logic will be applied to all modules. 1582 if (mCurrentModeIndex == ModulesInfo.MODULE_PHOTO 1583 || mCurrentModeIndex == ModulesInfo.MODULE_VIDEO) { 1584 if (oldModuleIndex != ModulesInfo.MODULE_PHOTO 1585 && oldModuleIndex != ModulesInfo.MODULE_VIDEO) { 1586 mCameraAppUI.prepareModuleUI(); 1587 } else { 1588 mCameraAppUI.clearModuleUI(); 1589 } 1590 } else { 1591 // This is the old way of removing all views in CameraRootView. Will 1592 // be deprecated soon. It is here to make sure modules that haven't 1593 // been refactored can still function. 1594 mCameraAppUI.clearCameraUI(); 1595 } 1596 1597 openModule(mCurrentModule); 1598 mCurrentModule.onOrientationChanged(mLastRawOrientation); 1599 if (mMediaSaver != null) { 1600 mCurrentModule.onMediaSaverAvailable(mMediaSaver); 1601 } 1602 // Store the module index so we can use it the next time the Camera 1603 // starts up. 1604 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 1605 prefs.edit().putInt(CameraSettings.KEY_STARTUP_MODULE_INDEX, modeIndex).apply(); 1606 } 1607 1608 public void onSettingsSelected() { 1609 // Temporary until we finalize the touch flow. 1610 LayoutInflater inflater = getLayoutInflater(); 1611 SettingsView settingsView = (SettingsView) inflater.inflate(R.layout.settings_list_layout, 1612 null, false); 1613 settingsView.setSettingsListener(mSettingsController); 1614 if (mFeedbackHelper != null) { 1615 settingsView.setFeedbackHelper(mFeedbackHelper); 1616 } 1617 PopupWindow popup = new PopupWindow(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 1618 popup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 1619 popup.setOutsideTouchable(true); 1620 popup.setFocusable(true); 1621 popup.setContentView(settingsView); 1622 popup.showAtLocation(mModeListView.getRootView(), Gravity.CENTER, 0, 0); 1623 } 1624 1625 /** 1626 * Sets the mCurrentModuleIndex, creates a new module instance for the given 1627 * index an sets it as mCurrentModule. 1628 */ 1629 private void setModuleFromModeIndex(int modeIndex) { 1630 ModuleManagerImpl.ModuleAgent agent = mModuleManager.getModuleAgent(modeIndex); 1631 if (agent == null) { 1632 return; 1633 } 1634 if (!agent.requestAppForCamera()) { 1635 mCameraController.closeCamera(); 1636 } 1637 mCurrentModeIndex = agent.getModuleId(); 1638 mCurrentModule = (CameraModule) agent.createModule(this); 1639 } 1640 1641 @Override 1642 public SettingsManager getSettingsManager() { 1643 return mSettingsManager; 1644 } 1645 1646 @Override 1647 public CameraServices getServices() { 1648 return (CameraServices) getApplication(); 1649 } 1650 1651 @Override 1652 public SettingsController getSettingsController() { 1653 return mSettingsController; 1654 } 1655 1656 /** 1657 * Creates an AlertDialog appropriate for choosing whether to enable location 1658 * on the first run of the app. 1659 */ 1660 public AlertDialog getFirstTimeLocationAlert() { 1661 AlertDialog.Builder builder = new AlertDialog.Builder(this); 1662 builder = SettingsView.getFirstTimeLocationAlertBuilder(builder, mSettingsController); 1663 if (builder != null) { 1664 return builder.create(); 1665 } else { 1666 return null; 1667 } 1668 } 1669 1670 /** 1671 * Launches an ACTION_EDIT intent for the given local data item. 1672 */ 1673 public void launchEditor(LocalData data) { 1674 Intent intent = new Intent(Intent.ACTION_EDIT) 1675 .setDataAndType(data.getContentUri(), data.getMimeType()) 1676 .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 1677 try { 1678 startActivityForResult(intent, REQ_CODE_DONT_SWITCH_TO_PREVIEW); 1679 } catch (ActivityNotFoundException e) { 1680 startActivityForResult(Intent.createChooser(intent, null), 1681 REQ_CODE_DONT_SWITCH_TO_PREVIEW); 1682 } 1683 } 1684 1685 /** 1686 * Launch the tiny planet editor. 1687 * 1688 * @param data The data must be a 360 degree stereographically mapped 1689 * panoramic image. It will not be modified, instead a new item 1690 * with the result will be added to the filmstrip. 1691 */ 1692 public void launchTinyPlanetEditor(LocalData data) { 1693 TinyPlanetFragment fragment = new TinyPlanetFragment(); 1694 Bundle bundle = new Bundle(); 1695 bundle.putString(TinyPlanetFragment.ARGUMENT_URI, data.getContentUri().toString()); 1696 bundle.putString(TinyPlanetFragment.ARGUMENT_TITLE, data.getTitle()); 1697 fragment.setArguments(bundle); 1698 fragment.show(getFragmentManager(), "tiny_planet"); 1699 } 1700 1701 private void openModule(CameraModule module) { 1702 module.init(this, isSecureCamera(), isCaptureIntent()); 1703 module.resume(); 1704 } 1705 1706 private void closeModule(CameraModule module) { 1707 module.pause(); 1708 } 1709 1710 private void performDeletion() { 1711 if (!mPendingDeletion) { 1712 return; 1713 } 1714 hideUndoDeletionBar(false); 1715 mDataAdapter.executeDeletion(CameraActivity.this); 1716 1717 int currentId = mFilmstripController.getCurrentId(); 1718 updateActionBarMenu(currentId); 1719 mFilmStripListener.onCurrentDataCentered(currentId); 1720 } 1721 1722 public void showUndoDeletionBar() { 1723 if (mPendingDeletion) { 1724 performDeletion(); 1725 } 1726 Log.v(TAG, "showing undo bar"); 1727 mPendingDeletion = true; 1728 if (mUndoDeletionBar == null) { 1729 ViewGroup v = (ViewGroup) getLayoutInflater().inflate(R.layout.undo_bar, 1730 mAboveFilmstripControlLayout, true); 1731 mUndoDeletionBar = (ViewGroup) v.findViewById(R.id.camera_undo_deletion_bar); 1732 View button = mUndoDeletionBar.findViewById(R.id.camera_undo_deletion_button); 1733 button.setOnClickListener(new View.OnClickListener() { 1734 @Override 1735 public void onClick(View view) { 1736 mDataAdapter.undoDataRemoval(); 1737 hideUndoDeletionBar(true); 1738 } 1739 }); 1740 // Setting undo bar clickable to avoid touch events going through 1741 // the bar to the buttons (eg. edit button, etc) underneath the bar. 1742 mUndoDeletionBar.setClickable(true); 1743 // When there is user interaction going on with the undo button, we 1744 // do not want to hide the undo bar. 1745 button.setOnTouchListener(new View.OnTouchListener() { 1746 @Override 1747 public boolean onTouch(View v, MotionEvent event) { 1748 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { 1749 mIsUndoingDeletion = true; 1750 } else if (event.getActionMasked() == MotionEvent.ACTION_UP) { 1751 mIsUndoingDeletion = false; 1752 } 1753 return false; 1754 } 1755 }); 1756 } 1757 mUndoDeletionBar.setAlpha(0f); 1758 mUndoDeletionBar.setVisibility(View.VISIBLE); 1759 mUndoDeletionBar.animate().setDuration(200).alpha(1f).setListener(null).start(); 1760 } 1761 1762 private void hideUndoDeletionBar(boolean withAnimation) { 1763 Log.v(TAG, "Hiding undo deletion bar"); 1764 mPendingDeletion = false; 1765 if (mUndoDeletionBar != null) { 1766 if (withAnimation) { 1767 mUndoDeletionBar.animate().setDuration(200).alpha(0f) 1768 .setListener(new Animator.AnimatorListener() { 1769 @Override 1770 public void onAnimationStart(Animator animation) { 1771 // Do nothing. 1772 } 1773 1774 @Override 1775 public void onAnimationEnd(Animator animation) { 1776 mUndoDeletionBar.setVisibility(View.GONE); 1777 } 1778 1779 @Override 1780 public void onAnimationCancel(Animator animation) { 1781 // Do nothing. 1782 } 1783 1784 @Override 1785 public void onAnimationRepeat(Animator animation) { 1786 // Do nothing. 1787 } 1788 }).start(); 1789 } else { 1790 mUndoDeletionBar.setVisibility(View.GONE); 1791 } 1792 } 1793 } 1794 1795 @Override 1796 public void onOrientationChanged(int orientation) { 1797 // We keep the last known orientation. So if the user first orient 1798 // the camera then point the camera to floor or sky, we still have 1799 // the correct orientation. 1800 if (orientation == OrientationManager.ORIENTATION_UNKNOWN) { 1801 return; 1802 } 1803 mLastRawOrientation = orientation; 1804 if (mCurrentModule != null) { 1805 mCurrentModule.onOrientationChanged(orientation); 1806 } 1807 } 1808 1809 /** 1810 * Enable/disable swipe-to-filmstrip. Will always disable swipe if in 1811 * capture intent. 1812 * 1813 * @param enable {@code true} to enable swipe. 1814 */ 1815 public void setSwipingEnabled(boolean enable) { 1816 if (isCaptureIntent()) { 1817 mCameraPreviewData.lockPreview(true); 1818 } else { 1819 mCameraPreviewData.lockPreview(!enable); 1820 } 1821 } 1822 1823 1824 /** 1825 * Check whether camera controls are visible. 1826 * 1827 * @return whether controls are visible. 1828 */ 1829 private boolean arePreviewControlsVisible() { 1830 return mCurrentModule.arePreviewControlsVisible(); 1831 } 1832 1833 /** 1834 * Show or hide the {@link CameraControls} using the current module's 1835 * implementation of {@link #onPreviewFocusChanged}. 1836 * 1837 * @param showControls whether to show camera controls. 1838 */ 1839 private void setPreviewControlsVisibility(boolean showControls) { 1840 mCurrentModule.onPreviewFocusChanged(showControls); 1841 } 1842 1843 // Accessor methods for getting latency times used in performance testing 1844 public long getAutoFocusTime() { 1845 return (mCurrentModule instanceof PhotoModule) ? 1846 ((PhotoModule) mCurrentModule).mAutoFocusTime : -1; 1847 } 1848 1849 public long getShutterLag() { 1850 return (mCurrentModule instanceof PhotoModule) ? 1851 ((PhotoModule) mCurrentModule).mShutterLag : -1; 1852 } 1853 1854 public long getShutterToPictureDisplayedTime() { 1855 return (mCurrentModule instanceof PhotoModule) ? 1856 ((PhotoModule) mCurrentModule).mShutterToPictureDisplayedTime : -1; 1857 } 1858 1859 public long getPictureDisplayedToJpegCallbackTime() { 1860 return (mCurrentModule instanceof PhotoModule) ? 1861 ((PhotoModule) mCurrentModule).mPictureDisplayedToJpegCallbackTime : -1; 1862 } 1863 1864 public long getJpegCallbackFinishTime() { 1865 return (mCurrentModule instanceof PhotoModule) ? 1866 ((PhotoModule) mCurrentModule).mJpegCallbackFinishTime : -1; 1867 } 1868 1869 public long getCaptureStartTime() { 1870 return (mCurrentModule instanceof PhotoModule) ? 1871 ((PhotoModule) mCurrentModule).mCaptureStartTime : -1; 1872 } 1873 1874 public boolean isRecording() { 1875 return (mCurrentModule instanceof VideoModule) ? 1876 ((VideoModule) mCurrentModule).isRecording() : false; 1877 } 1878 1879 public CameraManager.CameraOpenCallback getCameraOpenErrorCallback() { 1880 return mCameraController; 1881 } 1882 1883 // For debugging purposes only. 1884 public CameraModule getCurrentModule() { 1885 return mCurrentModule; 1886 } 1887 1888 private void keepScreenOnForAWhile() { 1889 if (mKeepScreenOn) { 1890 return; 1891 } 1892 mMainHandler.removeMessages(MSG_CLEAR_SCREEN_ON_FLAG); 1893 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 1894 mMainHandler.sendEmptyMessageDelayed(MSG_CLEAR_SCREEN_ON_FLAG, SCREEN_DELAY_MS); 1895 } 1896 1897 private void resetScreenOn() { 1898 mKeepScreenOn = false; 1899 mMainHandler.removeMessages(MSG_CLEAR_SCREEN_ON_FLAG); 1900 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 1901 } 1902} 1903