CameraActivity.java revision 42c07cc1cca3460c67a4243747074c822e11025f
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.animation.Animator; 20import android.annotation.TargetApi; 21import android.app.ActionBar; 22import android.app.Activity; 23import android.app.AlertDialog; 24import android.app.Dialog; 25import android.content.ActivityNotFoundException; 26import android.content.BroadcastReceiver; 27import android.content.ContentResolver; 28import android.content.Context; 29import android.content.Intent; 30import android.content.IntentFilter; 31import android.content.pm.ActivityInfo; 32import android.content.pm.PackageManager; 33import android.content.res.Configuration; 34import android.graphics.Bitmap; 35import android.graphics.BitmapFactory; 36import android.graphics.Matrix; 37import android.graphics.Point; 38import android.graphics.RectF; 39import android.graphics.SurfaceTexture; 40import android.graphics.drawable.Drawable; 41import android.hardware.Camera; 42import android.net.Uri; 43import android.nfc.NfcAdapter; 44import android.nfc.NfcAdapter.CreateBeamUrisCallback; 45import android.nfc.NfcEvent; 46import android.os.AsyncTask; 47import android.os.Build; 48import android.os.Bundle; 49import android.os.Handler; 50import android.os.HandlerThread; 51import android.os.Looper; 52import android.os.Message; 53import android.provider.MediaStore; 54import android.provider.Settings; 55import android.util.CameraPerformanceTracker; 56import android.view.ContextMenu; 57import android.view.ContextMenu.ContextMenuInfo; 58import android.view.KeyEvent; 59import android.view.Menu; 60import android.view.MenuInflater; 61import android.view.MenuItem; 62import android.view.MotionEvent; 63import android.view.View; 64import android.view.View.OnSystemUiVisibilityChangeListener; 65import android.view.ViewGroup; 66import android.view.Window; 67import android.view.WindowManager; 68import android.widget.FrameLayout; 69import android.widget.ImageView; 70import android.widget.ShareActionProvider; 71 72import com.android.camera.app.AppController; 73import com.android.camera.app.CameraAppUI; 74import com.android.camera.app.CameraController; 75import com.android.camera.app.CameraProvider; 76import com.android.camera.app.CameraServices; 77import com.android.camera.app.LocationManager; 78import com.android.camera.app.MemoryManager; 79import com.android.camera.app.MemoryQuery; 80import com.android.camera.app.ModuleManagerImpl; 81import com.android.camera.app.OrientationManager; 82import com.android.camera.app.OrientationManagerImpl; 83import com.android.camera.cameradevice.CameraManager; 84import com.android.camera.cameradevice.CameraManagerFactory; 85import com.android.camera.data.CameraDataAdapter; 86import com.android.camera.data.FixedLastDataAdapter; 87import com.android.camera.data.LocalData; 88import com.android.camera.data.LocalDataAdapter; 89import com.android.camera.data.LocalDataUtil; 90import com.android.camera.data.LocalDataViewType; 91import com.android.camera.data.LocalMediaData; 92import com.android.camera.data.LocalMediaObserver; 93import com.android.camera.data.LocalSessionData; 94import com.android.camera.data.MediaDetails; 95import com.android.camera.data.MetadataLoader; 96import com.android.camera.data.PanoramaMetadataLoader; 97import com.android.camera.data.RgbzMetadataLoader; 98import com.android.camera.data.SimpleViewData; 99import com.android.camera.debug.Log; 100import com.android.camera.filmstrip.FilmstripContentPanel; 101import com.android.camera.filmstrip.FilmstripController; 102import com.android.camera.hardware.HardwareSpec; 103import com.android.camera.hardware.HardwareSpecImpl; 104import com.android.camera.module.ModuleController; 105import com.android.camera.module.ModulesInfo; 106import com.android.camera.session.CaptureSession; 107import com.android.camera.session.CaptureSessionManager; 108import com.android.camera.session.CaptureSessionManager.SessionListener; 109import com.android.camera.settings.CameraSettingsActivity; 110import com.android.camera.settings.SettingsManager; 111import com.android.camera.settings.SettingsManager.SettingsCapabilities; 112import com.android.camera.settings.SettingsUtil; 113import com.android.camera.tinyplanet.TinyPlanetFragment; 114import com.android.camera.ui.AbstractTutorialOverlay; 115import com.android.camera.ui.DetailsDialog; 116import com.android.camera.ui.MainActivityLayout; 117import com.android.camera.ui.ModeListView; 118import com.android.camera.ui.ModeListView.ModeListVisibilityChangedListener; 119import com.android.camera.ui.PreviewStatusListener; 120import com.android.camera.util.ApiHelper; 121import com.android.camera.util.Callback; 122import com.android.camera.util.CameraUtil; 123import com.android.camera.util.FeedbackHelper; 124import com.android.camera.util.GalleryHelper; 125import com.android.camera.util.GcamHelper; 126import com.android.camera.util.IntentHelper; 127import com.android.camera.util.PhotoSphereHelper.PanoramaViewHelper; 128import com.android.camera.util.ReleaseDialogHelper; 129import com.android.camera.util.UsageStatistics; 130import com.android.camera.widget.FilmstripView; 131import com.android.camera.widget.Preloader; 132import com.android.camera2.R; 133import com.bumptech.glide.Glide; 134import com.bumptech.glide.resize.ImageManager; 135import com.google.common.logging.eventprotos; 136import com.google.common.logging.eventprotos.ForegroundEvent.ForegroundSource; 137import com.google.common.logging.eventprotos.MediaInteraction; 138import com.google.common.logging.eventprotos.NavigationChange; 139 140import java.io.File; 141import java.io.FileInputStream; 142import java.io.FileNotFoundException; 143import java.lang.ref.WeakReference; 144import java.util.ArrayList; 145import java.util.HashMap; 146import java.util.List; 147import java.util.concurrent.Executors; 148 149public class CameraActivity extends Activity 150 implements AppController, CameraManager.CameraOpenCallback, 151 ActionBar.OnMenuVisibilityListener, ShareActionProvider.OnShareTargetSelectedListener, 152 OrientationManager.OnOrientationChangeListener { 153 154 private static final Log.Tag TAG = new Log.Tag("CameraActivity"); 155 156 private static final String INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE = 157 "android.media.action.STILL_IMAGE_CAMERA_SECURE"; 158 public static final String ACTION_IMAGE_CAPTURE_SECURE = 159 "android.media.action.IMAGE_CAPTURE_SECURE"; 160 161 // The intent extra for camera from secure lock screen. True if the gallery 162 // should only show newly captured pictures. sSecureAlbumId does not 163 // increment. This is used when switching between camera, camcorder, and 164 // panorama. If the extra is not set, it is in the normal camera mode. 165 public static final String SECURE_CAMERA_EXTRA = "secure_camera"; 166 167 /** 168 * Request code from an activity we started that indicated that we do not 169 * want to reset the view to the preview in onResume. 170 */ 171 public static final int REQ_CODE_DONT_SWITCH_TO_PREVIEW = 142; 172 173 public static final int REQ_CODE_GCAM_DEBUG_POSTCAPTURE = 999; 174 175 private static final int MSG_CLEAR_SCREEN_ON_FLAG = 2; 176 private static final long SCREEN_DELAY_MS = 2 * 60 * 1000; // 2 mins. 177 private static final int MAX_PEEK_BITMAP_PIXELS = 1600000; // 1.6 * 4 MBs. 178 /** Load metadata for 10 items ahead of our current. */ 179 private static final int FILMSTRIP_PRELOAD_AHEAD_ITEMS = 10; 180 181 /** Should be used wherever a context is needed. */ 182 private Context mAppContext; 183 184 /** 185 * Whether onResume should reset the view to the preview. 186 */ 187 private boolean mResetToPreviewOnResume = true; 188 189 /** 190 * This data adapter is used by FilmStripView. 191 */ 192 private LocalDataAdapter mDataAdapter; 193 194 private SettingsManager mSettingsManager; 195 private ModeListView mModeListView; 196 private boolean mModeListVisible = false; 197 private int mCurrentModeIndex; 198 private CameraModule mCurrentModule; 199 private ModuleManagerImpl mModuleManager; 200 private FrameLayout mAboveFilmstripControlLayout; 201 private FilmstripController mFilmstripController; 202 private boolean mFilmstripVisible; 203 /** Whether the filmstrip fully covers the preview. */ 204 private boolean mFilmstripCoversPreview = false; 205 private int mResultCodeForTesting; 206 private Intent mResultDataForTesting; 207 private OnScreenHint mStorageHint; 208 private final Object mStorageSpaceLock = new Object(); 209 private long mStorageSpaceBytes = Storage.LOW_STORAGE_THRESHOLD_BYTES; 210 private boolean mAutoRotateScreen; 211 private boolean mSecureCamera; 212 private int mLastRawOrientation; 213 private OrientationManagerImpl mOrientationManager; 214 private LocationManager mLocationManager; 215 private ButtonManager mButtonManager; 216 private Handler mMainHandler; 217 private PanoramaViewHelper mPanoramaViewHelper; 218 private ActionBar mActionBar; 219 private ViewGroup mUndoDeletionBar; 220 private boolean mIsUndoingDeletion = false; 221 222 private final Uri[] mNfcPushUris = new Uri[1]; 223 224 private LocalMediaObserver mLocalImagesObserver; 225 private LocalMediaObserver mLocalVideosObserver; 226 227 private boolean mPendingDeletion = false; 228 229 private CameraController mCameraController; 230 private boolean mPaused; 231 private CameraAppUI mCameraAppUI; 232 233 private PeekAnimationHandler mPeekAnimationHandler; 234 private HandlerThread mPeekAnimationThread; 235 236 private FeedbackHelper mFeedbackHelper; 237 238 private Intent mGalleryIntent; 239 private long mOnCreateTime; 240 241 private Menu mActionBarMenu; 242 private Preloader<Integer, AsyncTask> mPreloader; 243 244 private static final int LIGHTS_OUT_DELAY_MS = 4000; 245 private final int BASE_SYS_UI_VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 246 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; 247 private final Runnable mLightsOutRunnable = new Runnable() { 248 @Override 249 public void run() { 250 getWindow().getDecorView().setSystemUiVisibility( 251 BASE_SYS_UI_VISIBILITY | View.SYSTEM_UI_FLAG_LOW_PROFILE); 252 } 253 }; 254 private MemoryManager mMemoryManager; 255 256 @Override 257 public CameraAppUI getCameraAppUI() { 258 return mCameraAppUI; 259 } 260 261 // close activity when screen turns off 262 private final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() { 263 @Override 264 public void onReceive(Context context, Intent intent) { 265 finish(); 266 } 267 }; 268 269 /** 270 * Whether the screen is kept turned on. 271 */ 272 private boolean mKeepScreenOn; 273 private int mLastLayoutOrientation; 274 private final CameraAppUI.BottomPanel.Listener mMyFilmstripBottomControlListener = 275 new CameraAppUI.BottomPanel.Listener() { 276 277 /** 278 * If the current photo is a photo sphere, this will launch the 279 * Photo Sphere panorama viewer. 280 */ 281 @Override 282 public void onExternalViewer() { 283 if (mPanoramaViewHelper == null) { 284 return; 285 } 286 final LocalData data = getCurrentLocalData(); 287 if (data == null) { 288 return; 289 } 290 final Uri contentUri = data.getUri(); 291 if (contentUri == Uri.EMPTY) { 292 return; 293 } 294 295 if (PanoramaMetadataLoader.isPanoramaAndUseViewer(data)) { 296 mPanoramaViewHelper.showPanorama(CameraActivity.this, contentUri); 297 } else if (RgbzMetadataLoader.hasRGBZData(data)) { 298 mPanoramaViewHelper.showRgbz(contentUri); 299 if (mSettingsManager.getBoolean( 300 SettingsManager.SETTING_SHOULD_SHOW_REFOCUS_VIEWER_CLING)) { 301 mSettingsManager.setBoolean( 302 SettingsManager.SETTING_SHOULD_SHOW_REFOCUS_VIEWER_CLING, 303 false); 304 mCameraAppUI.clearClingForViewer( 305 CameraAppUI.BottomPanel.VIEWER_REFOCUS); 306 } 307 } 308 } 309 310 @Override 311 public void onEdit() { 312 LocalData data = getCurrentLocalData(); 313 if (data == null) { 314 return; 315 } 316 final int currentDataId = getCurrentDataId(); 317 UsageStatistics.instance().mediaInteraction(fileNameFromDataID(currentDataId), 318 MediaInteraction.InteractionType.EDIT, 319 NavigationChange.InteractionCause.BUTTON, 320 fileAgeFromDataID(currentDataId)); 321 launchEditor(data); 322 } 323 324 @Override 325 public void onTinyPlanet() { 326 LocalData data = getCurrentLocalData(); 327 if (data == null) { 328 return; 329 } 330 launchTinyPlanetEditor(data); 331 } 332 333 @Override 334 public void onDelete() { 335 final int currentDataId = getCurrentDataId(); 336 UsageStatistics.instance().mediaInteraction(fileNameFromDataID(currentDataId), 337 MediaInteraction.InteractionType.DELETE, 338 NavigationChange.InteractionCause.BUTTON, 339 fileAgeFromDataID(currentDataId)); 340 removeData(currentDataId); 341 } 342 343 @Override 344 public void onShare() { 345 final LocalData data = getCurrentLocalData(); 346 final int currentDataId = getCurrentDataId(); 347 UsageStatistics.instance().mediaInteraction(fileNameFromDataID(currentDataId), 348 MediaInteraction.InteractionType.SHARE, 349 NavigationChange.InteractionCause.BUTTON, 350 fileAgeFromDataID(currentDataId)); 351 // If applicable, show release information before this item 352 // is shared. 353 if (ReleaseDialogHelper.shouldShowReleaseInfoDialogOnShare(data)) { 354 ReleaseDialogHelper.showReleaseInfoDialog(CameraActivity.this, 355 new Callback<Void>() { 356 @Override 357 public void onCallback(Void result) { 358 share(data); 359 } 360 }); 361 } else { 362 share(data); 363 } 364 } 365 366 private void share(LocalData data) { 367 Intent shareIntent = getShareIntentByData(data); 368 if (shareIntent != null) { 369 try { 370 launchActivityByIntent(shareIntent); 371 mCameraAppUI.getFilmstripBottomControls().setShareEnabled(false); 372 } catch (ActivityNotFoundException ex) { 373 // Nothing. 374 } 375 } 376 } 377 378 private int getCurrentDataId() { 379 return mFilmstripController.getCurrentId(); 380 } 381 382 private LocalData getCurrentLocalData() { 383 return mDataAdapter.getLocalData(getCurrentDataId()); 384 } 385 386 /** 387 * Sets up the share intent and NFC properly according to the 388 * data. 389 * 390 * @param data The data to be shared. 391 */ 392 private Intent getShareIntentByData(final LocalData data) { 393 Intent intent = null; 394 final Uri contentUri = data.getUri(); 395 final String msgShareTo = getResources().getString(R.string.share_to); 396 397 if (PanoramaMetadataLoader.isPanorama360(data) && 398 data.getUri() != Uri.EMPTY) { 399 intent = new Intent(Intent.ACTION_SEND); 400 intent.setType("application/vnd.google.panorama360+jpg"); 401 intent.putExtra(Intent.EXTRA_STREAM, contentUri); 402 } else if (data.isDataActionSupported(LocalData.DATA_ACTION_SHARE)) { 403 final String mimeType = data.getMimeType(); 404 intent = getShareIntentFromType(mimeType); 405 if (intent != null) { 406 intent.putExtra(Intent.EXTRA_STREAM, contentUri); 407 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 408 } 409 intent = Intent.createChooser(intent, msgShareTo); 410 } 411 return intent; 412 } 413 414 /** 415 * Get the share intent according to the mimeType 416 * 417 * @param mimeType The mimeType of current data. 418 * @return the video/image's ShareIntent or null if mimeType is 419 * invalid. 420 */ 421 private Intent getShareIntentFromType(String mimeType) { 422 // Lazily create the intent object. 423 Intent intent = new Intent(Intent.ACTION_SEND); 424 if (mimeType.startsWith("video/")) { 425 intent.setType("video/*"); 426 } else { 427 if (mimeType.startsWith("image/")) { 428 intent.setType("image/*"); 429 } else { 430 Log.w(TAG, "unsupported mimeType " + mimeType); 431 } 432 } 433 return intent; 434 } 435 436 @Override 437 public void onProgressErrorClicked() { 438 LocalData data = getCurrentLocalData(); 439 getServices().getCaptureSessionManager().removeErrorMessage( 440 data.getUri()); 441 updateBottomControlsByData(data); 442 } 443 }; 444 445 @Override 446 public void onCameraOpened(CameraManager.CameraProxy camera) { 447 if (mPaused) { 448 return; 449 } 450 /** 451 * The current UI requires that the flash option visibility in front-facing 452 * camera be 453 * * disabled if back facing camera supports flash 454 * * hidden if back facing camera does not support flash 455 * We save whether back facing camera supports flash because we cannot get 456 * this in front facing camera without a camera switch. 457 * 458 * If this preference is cleared, we also need to clear the camera facing 459 * setting so we default to opening the camera in back facing camera, and 460 * can save this flash support value again. 461 */ 462 if (!mSettingsManager.isSet(SettingsManager.SETTING_FLASH_SUPPORTED_BACK_CAMERA)) { 463 HardwareSpec hardware = new HardwareSpecImpl(camera.getParameters()); 464 mSettingsManager.setBoolean(SettingsManager.SETTING_FLASH_SUPPORTED_BACK_CAMERA, 465 hardware.isFlashSupported()); 466 } 467 468 if (!mModuleManager.getModuleAgent(mCurrentModeIndex).requestAppForCamera()) { 469 // We shouldn't be here. Just close the camera and leave. 470 mCameraController.closeCamera(false); 471 throw new IllegalStateException("Camera opened but the module shouldn't be " + 472 "requesting"); 473 } 474 if (mCurrentModule != null) { 475 SettingsCapabilities capabilities = 476 SettingsUtil.getSettingsCapabilities(camera); 477 mSettingsManager.changeCamera(camera.getCameraId(), capabilities); 478 resetExposureCompensationToDefault(camera); 479 mCurrentModule.onCameraAvailable(camera); 480 } 481 mCameraAppUI.onChangeCamera(); 482 } 483 484 private void resetExposureCompensationToDefault(CameraManager.CameraProxy camera) { 485 // Reset the exposure compensation before handing the camera to module. 486 Camera.Parameters parameters = camera.getParameters(); 487 parameters.setExposureCompensation(0); 488 camera.setParameters(parameters); 489 } 490 491 @Override 492 public void onCameraDisabled(int cameraId) { 493 UsageStatistics.instance().cameraFailure(eventprotos.CameraFailure.FailureReason.SECURITY, 494 null); 495 Log.w(TAG, "Camera disabled: " + cameraId); 496 CameraUtil.showErrorAndFinish(this, R.string.camera_disabled); 497 } 498 499 @Override 500 public void onDeviceOpenFailure(int cameraId, String info) { 501 UsageStatistics.instance().cameraFailure( 502 eventprotos.CameraFailure.FailureReason.OPEN_FAILURE, info); 503 Log.w(TAG, "Camera open failure: " + info); 504 CameraUtil.showErrorAndFinish(this, R.string.cannot_connect_camera); 505 } 506 507 @Override 508 public void onDeviceOpenedAlready(int cameraId, String info) { 509 Log.w(TAG, "Camera open already: " + cameraId + "," + info); 510 CameraUtil.showErrorAndFinish(this, R.string.cannot_connect_camera); 511 } 512 513 @Override 514 public void onReconnectionFailure(CameraManager mgr, String info) { 515 UsageStatistics.instance().cameraFailure( 516 eventprotos.CameraFailure.FailureReason.RECONNECT_FAILURE, null); 517 Log.w(TAG, "Camera reconnection failure:" + info); 518 CameraUtil.showErrorAndFinish(this, R.string.cannot_connect_camera); 519 } 520 521 private static class MainHandler extends Handler { 522 final WeakReference<CameraActivity> mActivity; 523 524 public MainHandler(CameraActivity activity, Looper looper) { 525 super(looper); 526 mActivity = new WeakReference<CameraActivity>(activity); 527 } 528 529 @Override 530 public void handleMessage(Message msg) { 531 CameraActivity activity = mActivity.get(); 532 if (activity == null) { 533 return; 534 } 535 switch (msg.what) { 536 537 case MSG_CLEAR_SCREEN_ON_FLAG: { 538 if (!activity.mPaused) { 539 activity.getWindow().clearFlags( 540 WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 541 } 542 break; 543 } 544 } 545 } 546 } 547 548 private String fileNameFromDataID(int dataID) { 549 final LocalData localData = mDataAdapter.getLocalData(dataID); 550 551 File localFile = new File(localData.getPath()); 552 return localFile.getName(); 553 } 554 555 private float fileAgeFromDataID(int dataID) { 556 final LocalData localData = mDataAdapter.getLocalData(dataID); 557 558 File localFile = new File(localData.getPath()); 559 return 0.001f * (System.currentTimeMillis() - localFile.lastModified()); 560 } 561 562 private final FilmstripContentPanel.Listener mFilmstripListener = 563 new FilmstripContentPanel.Listener() { 564 565 @Override 566 public void onSwipeOut() { 567 } 568 569 @Override 570 public void onSwipeOutBegin() { 571 mActionBar.hide(); 572 mFilmstripCoversPreview = false; 573 updatePreviewVisibility(); 574 } 575 576 @Override 577 public void onFilmstripHidden() { 578 mFilmstripVisible = false; 579 UsageStatistics.instance().changeScreen(currentUserInterfaceMode(), 580 NavigationChange.InteractionCause.SWIPE_RIGHT); 581 CameraActivity.this.setFilmstripUiVisibility(false); 582 // When the user hide the filmstrip (either swipe out or 583 // tap on back key) we move to the first item so next time 584 // when the user swipe in the filmstrip, the most recent 585 // one is shown. 586 mFilmstripController.goToFirstItem(); 587 } 588 589 @Override 590 public void onFilmstripShown() { 591 mFilmstripVisible = true; 592 UsageStatistics.instance().changeScreen(currentUserInterfaceMode(), 593 NavigationChange.InteractionCause.SWIPE_LEFT); 594 updateUiByData(mFilmstripController.getCurrentId()); 595 } 596 597 @Override 598 public void onFocusedDataLongPressed(int dataId) { 599 // Do nothing. 600 } 601 602 @Override 603 public void onFocusedDataPromoted(int dataID) { 604 UsageStatistics.instance().mediaInteraction(fileNameFromDataID(dataID), 605 MediaInteraction.InteractionType.DELETE, 606 NavigationChange.InteractionCause.SWIPE_UP, fileAgeFromDataID(dataID)); 607 removeData(dataID); 608 } 609 610 @Override 611 public void onFocusedDataDemoted(int dataID) { 612 UsageStatistics.instance().mediaInteraction(fileNameFromDataID(dataID), 613 MediaInteraction.InteractionType.DELETE, 614 NavigationChange.InteractionCause.SWIPE_DOWN, 615 fileAgeFromDataID(dataID)); 616 removeData(dataID); 617 } 618 619 @Override 620 public void onEnterFullScreenUiShown(int dataId) { 621 if (mFilmstripVisible) { 622 CameraActivity.this.setFilmstripUiVisibility(true); 623 } 624 } 625 626 @Override 627 public void onLeaveFullScreenUiShown(int dataId) { 628 // Do nothing. 629 } 630 631 @Override 632 public void onEnterFullScreenUiHidden(int dataId) { 633 if (mFilmstripVisible) { 634 CameraActivity.this.setFilmstripUiVisibility(false); 635 } 636 } 637 638 @Override 639 public void onLeaveFullScreenUiHidden(int dataId) { 640 // Do nothing. 641 } 642 643 @Override 644 public void onEnterFilmstrip(int dataId) { 645 if (mFilmstripVisible) { 646 CameraActivity.this.setFilmstripUiVisibility(true); 647 } 648 } 649 650 @Override 651 public void onLeaveFilmstrip(int dataId) { 652 // Do nothing. 653 } 654 655 @Override 656 public void onDataReloaded() { 657 if (!mFilmstripVisible) { 658 return; 659 } 660 updateUiByData(mFilmstripController.getCurrentId()); 661 } 662 663 @Override 664 public void onDataUpdated(int dataId) { 665 if (!mFilmstripVisible) { 666 return; 667 } 668 updateUiByData(mFilmstripController.getCurrentId()); 669 } 670 671 @Override 672 public void onEnterZoomView(int dataID) { 673 if (mFilmstripVisible) { 674 CameraActivity.this.setFilmstripUiVisibility(false); 675 } 676 } 677 678 @Override 679 public void onDataFocusChanged(final int prevDataId, final int newDataId) { 680 if (!mFilmstripVisible) { 681 return; 682 } 683 // TODO: This callback is UI event callback, should always 684 // happen on UI thread. Find the reason for this 685 // runOnUiThread() and fix it. 686 runOnUiThread(new Runnable() { 687 @Override 688 public void run() { 689 updateUiByData(newDataId); 690 } 691 }); 692 } 693 694 @Override 695 public void onScroll(int firstVisiblePosition, int visibleItemCount, int totalItemCount) { 696 mPreloader.onScroll(null /*absListView*/, firstVisiblePosition, visibleItemCount, totalItemCount); 697 } 698 }; 699 700 private final LocalDataAdapter.LocalDataListener mLocalDataListener = 701 new LocalDataAdapter.LocalDataListener() { 702 @Override 703 public void onMetadataUpdated(List<Integer> updatedData) { 704 if (mPaused) { 705 // Callback after the activity is paused. 706 return; 707 } 708 int currentDataId = mFilmstripController.getCurrentId(); 709 for (Integer dataId : updatedData) { 710 if (dataId == currentDataId) { 711 updateBottomControlsByData(mDataAdapter.getLocalData(dataId)); 712 // Currently we have only 1 data can be matched. 713 // No need to look for more, break. 714 break; 715 } 716 } 717 } 718 }; 719 720 public void gotoGallery() { 721 UsageStatistics.instance().changeScreen(NavigationChange.Mode.FILMSTRIP, 722 NavigationChange.InteractionCause.BUTTON); 723 724 mFilmstripController.goToNextItem(); 725 } 726 727 /** 728 * If 'visible' is false, this hides the action bar. Also maintains 729 * lights-out at all times. 730 * 731 * @param visible is false, this hides the action bar and filmstrip bottom 732 * controls. 733 */ 734 private void setFilmstripUiVisibility(boolean visible) { 735 mLightsOutRunnable.run(); 736 mCameraAppUI.getFilmstripBottomControls().setVisible(visible); 737 if (visible != mActionBar.isShowing()) { 738 if (visible) { 739 mActionBar.show(); 740 } else { 741 mActionBar.hide(); 742 } 743 } 744 mFilmstripCoversPreview = visible; 745 updatePreviewVisibility(); 746 } 747 748 private void hideSessionProgress() { 749 mCameraAppUI.getFilmstripBottomControls().hideProgress(); 750 } 751 752 private void showSessionProgress(CharSequence message) { 753 CameraAppUI.BottomPanel controls = mCameraAppUI.getFilmstripBottomControls(); 754 controls.setProgressText(message); 755 controls.hideControls(); 756 controls.hideProgressError(); 757 controls.showProgress(); 758 } 759 760 private void showProcessError(CharSequence message) { 761 mCameraAppUI.getFilmstripBottomControls().showProgressError(message); 762 } 763 764 private void updateSessionProgress(int progress) { 765 mCameraAppUI.getFilmstripBottomControls().setProgress(progress); 766 } 767 768 private void updateSessionProgressText(CharSequence message) { 769 mCameraAppUI.getFilmstripBottomControls().setProgressText(message); 770 } 771 772 @TargetApi(Build.VERSION_CODES.JELLY_BEAN) 773 private void setupNfcBeamPush() { 774 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mAppContext); 775 if (adapter == null) { 776 return; 777 } 778 779 if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS) { 780 // Disable beaming 781 adapter.setNdefPushMessage(null, CameraActivity.this); 782 return; 783 } 784 785 adapter.setBeamPushUris(null, CameraActivity.this); 786 adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() { 787 @Override 788 public Uri[] createBeamUris(NfcEvent event) { 789 return mNfcPushUris; 790 } 791 }, CameraActivity.this); 792 } 793 794 @Override 795 public void onMenuVisibilityChanged(boolean isVisible) { 796 // TODO: Remove this or bring back the original implementation: cancel 797 // auto-hide actionbar. 798 } 799 800 @Override 801 public boolean onShareTargetSelected(ShareActionProvider shareActionProvider, Intent intent) { 802 int currentDataId = mFilmstripController.getCurrentId(); 803 if (currentDataId < 0) { 804 return false; 805 } 806 UsageStatistics.instance().mediaInteraction(fileNameFromDataID(currentDataId), 807 MediaInteraction.InteractionType.SHARE, 808 NavigationChange.InteractionCause.BUTTON, fileAgeFromDataID(currentDataId)); 809 // TODO add intent.getComponent().getPackageName() 810 return true; 811 } 812 813 // Note: All callbacks come back on the main thread. 814 private final SessionListener mSessionListener = 815 new SessionListener() { 816 @Override 817 public void onSessionQueued(final Uri uri) { 818 if (!Storage.isSessionUri(uri)) { 819 return; 820 } 821 LocalSessionData newData = new LocalSessionData(uri); 822 mDataAdapter.addData(newData); 823 } 824 825 @Override 826 public void onSessionDone(final Uri sessionUri) { 827 Log.v(TAG, "onSessionDone:" + sessionUri); 828 Uri contentUri = Storage.getContentUriForSessionUri(sessionUri); 829 if (contentUri == null) { 830 mDataAdapter.refresh(sessionUri); 831 return; 832 } 833 LocalData newData = LocalMediaData.PhotoData.fromContentUri( 834 getContentResolver(), contentUri); 835 836 final int pos = mDataAdapter.findDataByContentUri(sessionUri); 837 if (pos == -1) { 838 // We do not have a placeholder for this image, perhaps 839 // due to the activity crashing or being killed. 840 mDataAdapter.addData(newData); 841 } else { 842 mDataAdapter.updateData(pos, newData); 843 } 844 } 845 846 @Override 847 public void onSessionProgress(final Uri uri, final int progress) { 848 if (progress < 0) { 849 // Do nothing, there is no task for this URI. 850 return; 851 } 852 int currentDataId = mFilmstripController.getCurrentId(); 853 if (currentDataId == -1) { 854 return; 855 } 856 if (uri.equals( 857 mDataAdapter.getLocalData(currentDataId).getUri())) { 858 updateSessionProgress(progress); 859 } 860 } 861 862 @Override 863 public void onSessionProgressText(final Uri uri, final CharSequence message) { 864 int currentDataId = mFilmstripController.getCurrentId(); 865 if (currentDataId == -1) { 866 return; 867 } 868 if (uri.equals( 869 mDataAdapter.getLocalData(currentDataId).getUri())) { 870 updateSessionProgressText(message); 871 } 872 } 873 874 @Override 875 public void onSessionUpdated(Uri uri) { 876 mDataAdapter.refresh(uri); 877 } 878 879 @Override 880 public void onSessionPreviewAvailable(Uri uri) { 881 mDataAdapter.refresh(uri); 882 int dataId = mDataAdapter.findDataByContentUri(uri); 883 if (dataId != -1) { 884 startPeekAnimation(mDataAdapter.getLocalData(dataId)); 885 } 886 } 887 888 @Override 889 public void onSessionFailed(Uri uri, CharSequence reason) { 890 Log.v(TAG, "onSessionFailed:" + uri); 891 892 int failedDataId = mDataAdapter.findDataByContentUri(uri); 893 int currentDataId = mFilmstripController.getCurrentId(); 894 895 if (currentDataId == failedDataId) { 896 updateSessionProgress(0); 897 showProcessError(reason); 898 } 899 // HERE 900 mDataAdapter.refresh(uri); 901 } 902 }; 903 904 @Override 905 public Context getAndroidContext() { 906 return mAppContext; 907 } 908 909 @Override 910 public void launchActivityByIntent(Intent intent) { 911 startActivityForResult(intent, REQ_CODE_DONT_SWITCH_TO_PREVIEW); 912 } 913 914 @Override 915 public int getCurrentModuleIndex() { 916 return mCurrentModeIndex; 917 } 918 919 @Override 920 public ModuleController getCurrentModuleController() { 921 return mCurrentModule; 922 } 923 924 @Override 925 public int getQuickSwitchToModuleId(int currentModuleIndex) { 926 return mModuleManager.getQuickSwitchToModuleId(currentModuleIndex, mSettingsManager, 927 mAppContext); 928 } 929 930 @Override 931 public SurfaceTexture getPreviewBuffer() { 932 // TODO: implement this 933 return null; 934 } 935 936 @Override 937 public void onPreviewReadyToStart() { 938 mCameraAppUI.onPreviewReadyToStart(); 939 } 940 941 @Override 942 public void onPreviewStarted() { 943 mCameraAppUI.onPreviewStarted(); 944 } 945 946 @Override 947 public void addPreviewAreaSizeChangedListener( 948 PreviewStatusListener.PreviewAreaChangedListener listener) { 949 mCameraAppUI.addPreviewAreaChangedListener(listener); 950 } 951 952 @Override 953 public void removePreviewAreaSizeChangedListener( 954 PreviewStatusListener.PreviewAreaChangedListener listener) { 955 mCameraAppUI.removePreviewAreaChangedListener(listener); 956 } 957 958 @Override 959 public void setupOneShotPreviewListener() { 960 mCameraController.setOneShotPreviewCallback(mMainHandler, 961 new CameraManager.CameraPreviewDataCallback() { 962 @Override 963 public void onPreviewFrame(byte[] data, CameraManager.CameraProxy camera) { 964 mCurrentModule.onPreviewInitialDataReceived(); 965 mCameraAppUI.onNewPreviewFrame(); 966 } 967 } 968 ); 969 } 970 971 @Override 972 public void updatePreviewAspectRatio(float aspectRatio) { 973 mCameraAppUI.updatePreviewAspectRatio(aspectRatio); 974 } 975 976 @Override 977 public void updatePreviewTransformFullscreen(Matrix matrix, float aspectRatio) { 978 mCameraAppUI.updatePreviewTransformFullscreen(matrix, aspectRatio); 979 } 980 981 @Override 982 public RectF getFullscreenRect() { 983 return mCameraAppUI.getFullscreenRect(); 984 } 985 986 @Override 987 public void updatePreviewTransform(Matrix matrix) { 988 mCameraAppUI.updatePreviewTransform(matrix); 989 } 990 991 @Override 992 public void setPreviewStatusListener(PreviewStatusListener previewStatusListener) { 993 mCameraAppUI.setPreviewStatusListener(previewStatusListener); 994 } 995 996 @Override 997 public FrameLayout getModuleLayoutRoot() { 998 return mCameraAppUI.getModuleRootView(); 999 } 1000 1001 @Override 1002 public void setShutterEventsListener(ShutterEventsListener listener) { 1003 // TODO: implement this 1004 } 1005 1006 @Override 1007 public void setShutterEnabled(boolean enabled) { 1008 mCameraAppUI.setShutterButtonEnabled(enabled); 1009 } 1010 1011 @Override 1012 public boolean isShutterEnabled() { 1013 return mCameraAppUI.isShutterButtonEnabled(); 1014 } 1015 1016 @Override 1017 public void startPreCaptureAnimation() { 1018 mCameraAppUI.startPreCaptureAnimation(); 1019 } 1020 1021 @Override 1022 public void cancelPreCaptureAnimation() { 1023 // TODO: implement this 1024 } 1025 1026 @Override 1027 public void startPostCaptureAnimation() { 1028 // TODO: implement this 1029 } 1030 1031 @Override 1032 public void startPostCaptureAnimation(Bitmap thumbnail) { 1033 // TODO: implement this 1034 } 1035 1036 @Override 1037 public void cancelPostCaptureAnimation() { 1038 // TODO: implement this 1039 } 1040 1041 @Override 1042 public OrientationManager getOrientationManager() { 1043 return mOrientationManager; 1044 } 1045 1046 @Override 1047 public LocationManager getLocationManager() { 1048 return mLocationManager; 1049 } 1050 1051 @Override 1052 public void lockOrientation() { 1053 if (mOrientationManager != null) { 1054 mOrientationManager.lockOrientation(); 1055 } 1056 } 1057 1058 @Override 1059 public void unlockOrientation() { 1060 if (mOrientationManager != null) { 1061 mOrientationManager.unlockOrientation(); 1062 } 1063 } 1064 1065 /** 1066 * Starts the filmstrip peek animation if the filmstrip is not visible. 1067 * Only {@link LocalData#LOCAL_IMAGE}, {@link 1068 * LocalData#LOCAL_IN_PROGRESS_DATA} and {@link 1069 * LocalData#LOCAL_VIDEO} are supported. 1070 * 1071 * @param data The data to peek. 1072 */ 1073 private void startPeekAnimation(final LocalData data) { 1074 if (mFilmstripVisible || mPeekAnimationHandler == null) { 1075 return; 1076 } 1077 1078 int dataType = data.getLocalDataType(); 1079 if (dataType != LocalData.LOCAL_IMAGE && dataType != LocalData.LOCAL_IN_PROGRESS_DATA && 1080 dataType != LocalData.LOCAL_VIDEO) { 1081 return; 1082 } 1083 1084 mPeekAnimationHandler.startDecodingJob(data, new Callback<Bitmap>() { 1085 @Override 1086 public void onCallback(Bitmap result) { 1087 mCameraAppUI.startPeekAnimation(result, true); 1088 } 1089 }); 1090 } 1091 1092 @Override 1093 public void notifyNewMedia(Uri uri) { 1094 updateStorageSpaceAndHint(null); 1095 ContentResolver cr = getContentResolver(); 1096 String mimeType = cr.getType(uri); 1097 LocalData newData = null; 1098 if (LocalDataUtil.isMimeTypeVideo(mimeType)) { 1099 sendBroadcast(new Intent(CameraUtil.ACTION_NEW_VIDEO, uri)); 1100 newData = LocalMediaData.VideoData.fromContentUri(getContentResolver(), uri); 1101 if (newData == null) { 1102 Log.e(TAG, "Can't find video data in content resolver:" + uri); 1103 return; 1104 } 1105 } else if (LocalDataUtil.isMimeTypeImage(mimeType)) { 1106 CameraUtil.broadcastNewPicture(mAppContext, uri); 1107 newData = LocalMediaData.PhotoData.fromContentUri(getContentResolver(), uri); 1108 if (newData == null) { 1109 Log.e(TAG, "Can't find photo data in content resolver:" + uri); 1110 return; 1111 } 1112 } else { 1113 Log.w(TAG, "Unknown new media with MIME type:" + mimeType + ", uri:" + uri); 1114 return; 1115 } 1116 // We are preloading the metadata for new video since we need the 1117 // rotation info for the thumbnail. 1118 new AsyncTask<LocalData, Void, LocalData>() { 1119 1120 @Override 1121 protected LocalData doInBackground(LocalData... params) { 1122 LocalData data = params[0]; 1123 MetadataLoader.loadMetadata(getAndroidContext(), data); 1124 return data; 1125 } 1126 1127 @Override 1128 protected void onPostExecute(LocalData data) { 1129 if (mDataAdapter.addData(data)) { 1130 startPeekAnimation(data); 1131 } 1132 } 1133 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, newData); 1134 } 1135 1136 @Override 1137 public void enableKeepScreenOn(boolean enabled) { 1138 if (mPaused) { 1139 return; 1140 } 1141 1142 mKeepScreenOn = enabled; 1143 if (mKeepScreenOn) { 1144 mMainHandler.removeMessages(MSG_CLEAR_SCREEN_ON_FLAG); 1145 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 1146 } else { 1147 keepScreenOnForAWhile(); 1148 } 1149 } 1150 1151 @Override 1152 public CameraProvider getCameraProvider() { 1153 return mCameraController; 1154 } 1155 1156 private void removeData(int dataID) { 1157 mDataAdapter.removeData(dataID); 1158 if (mDataAdapter.getTotalNumber() > 1) { 1159 showUndoDeletionBar(); 1160 } else { 1161 // If camera preview is the only view left in filmstrip, 1162 // no need to show undo bar. 1163 mPendingDeletion = true; 1164 performDeletion(); 1165 if (mFilmstripVisible) { 1166 mCameraAppUI.getFilmstripContentPanel().animateHide(); 1167 } 1168 } 1169 } 1170 1171 @Override 1172 public boolean onOptionsItemSelected(MenuItem item) { 1173 // Handle presses on the action bar items 1174 switch (item.getItemId()) { 1175 case android.R.id.home: 1176 if (mFilmstripVisible && startGallery()) { 1177 return true; 1178 } 1179 onBackPressed(); 1180 return true; 1181 case R.id.action_details: 1182 showDetailsDialog(mFilmstripController.getCurrentId()); 1183 return true; 1184 default: 1185 return super.onOptionsItemSelected(item); 1186 } 1187 } 1188 1189 private boolean isCaptureIntent() { 1190 if (MediaStore.ACTION_VIDEO_CAPTURE.equals(getIntent().getAction()) 1191 || MediaStore.ACTION_IMAGE_CAPTURE.equals(getIntent().getAction()) 1192 || MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(getIntent().getAction())) { 1193 return true; 1194 } else { 1195 return false; 1196 } 1197 } 1198 1199 private final CameraManager.CameraExceptionCallback mCameraDefaultExceptionCallback 1200 = new CameraManager.CameraExceptionCallback() { 1201 @Override 1202 public void onCameraException(RuntimeException e) { 1203 Log.e(TAG, "Camera Exception", e); 1204 CameraUtil.showErrorAndFinish(CameraActivity.this, 1205 R.string.cannot_connect_camera); 1206 } 1207 }; 1208 1209 @Override 1210 public void onCreate(Bundle state) { 1211 CameraPerformanceTracker.onEvent(CameraPerformanceTracker.ACTIVITY_START); 1212 1213 super.onCreate(state); 1214 final Glide glide = Glide.get(); 1215 if (!glide.isImageManagerSet()) { 1216 // We load exclusively large images, so we want fewer threads to minimize jank. 1217 glide.setImageManager(new ImageManager.Builder(getApplicationContext()) 1218 .setResizeService(Executors.newSingleThreadExecutor())); 1219 } 1220 1221 mOnCreateTime = System.currentTimeMillis(); 1222 mAppContext = getApplicationContext(); 1223 mSettingsManager = new SettingsManager(mAppContext, this); 1224 GcamHelper.init(getContentResolver()); 1225 1226 getWindow().requestFeature(Window.FEATURE_ACTION_BAR); 1227 setContentView(R.layout.activity_main); 1228 mActionBar = getActionBar(); 1229 mActionBar.addOnMenuVisibilityListener(this); 1230 mMainHandler = new MainHandler(this, getMainLooper()); 1231 mCameraController = 1232 new CameraController(mAppContext, this, mMainHandler, 1233 CameraManagerFactory.getAndroidCameraManager()); 1234 mCameraController.setCameraDefaultExceptionCallback(mCameraDefaultExceptionCallback, 1235 mMainHandler); 1236 1237 // TODO: Try to move all the resources allocation to happen as soon as 1238 // possible so we can call module.init() at the earliest time. 1239 mModuleManager = new ModuleManagerImpl(); 1240 ModulesInfo.setupModules(mAppContext, mModuleManager); 1241 1242 mModeListView = (ModeListView) findViewById(R.id.mode_list_layout); 1243 mModeListView.init(mModuleManager.getSupportedModeIndexList()); 1244 if (ApiHelper.HAS_ROTATION_ANIMATION) { 1245 setRotationAnimation(); 1246 } 1247 mModeListView.setVisibilityChangedListener(new ModeListVisibilityChangedListener() { 1248 @Override 1249 public void onVisibilityChanged(boolean visible) { 1250 mModeListVisible = visible; 1251 updatePreviewVisibility(); 1252 } 1253 }); 1254 1255 // Check if this is in the secure camera mode. 1256 Intent intent = getIntent(); 1257 String action = intent.getAction(); 1258 if (INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action) 1259 || ACTION_IMAGE_CAPTURE_SECURE.equals(action)) { 1260 mSecureCamera = true; 1261 } else { 1262 mSecureCamera = intent.getBooleanExtra(SECURE_CAMERA_EXTRA, false); 1263 } 1264 1265 if (mSecureCamera) { 1266 // Foreground event caused by lock screen startup. 1267 // It is necessary to log this in onCreate, to avoid the 1268 // onResume->onPause->onResume sequence. 1269 UsageStatistics.instance().foregrounded(ForegroundSource.ACTION_IMAGE_CAPTURE_SECURE, 1270 currentUserInterfaceMode()); 1271 1272 // Change the window flags so that secure camera can show when 1273 // locked 1274 Window win = getWindow(); 1275 WindowManager.LayoutParams params = win.getAttributes(); 1276 params.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; 1277 win.setAttributes(params); 1278 1279 // Filter for screen off so that we can finish secure camera 1280 // activity 1281 // when screen is off. 1282 IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); 1283 registerReceiver(mScreenOffReceiver, filter); 1284 } 1285 mCameraAppUI = new CameraAppUI(this, 1286 (MainActivityLayout) findViewById(R.id.activity_root_view), isCaptureIntent()); 1287 1288 mCameraAppUI.setFilmstripBottomControlsListener(mMyFilmstripBottomControlListener); 1289 1290 mAboveFilmstripControlLayout = 1291 (FrameLayout) findViewById(R.id.camera_filmstrip_content_layout); 1292 1293 // Add the session listener so we can track the session progress 1294 // updates. 1295 getServices().getCaptureSessionManager().addSessionListener(mSessionListener); 1296 mFilmstripController = ((FilmstripView) findViewById(R.id.filmstrip_view)).getController(); 1297 mFilmstripController.setImageGap( 1298 getResources().getDimensionPixelSize(R.dimen.camera_film_strip_gap)); 1299 mPanoramaViewHelper = new PanoramaViewHelper(this); 1300 mPanoramaViewHelper.onCreate(); 1301 // Set up the camera preview first so the preview shows up ASAP. 1302 mDataAdapter = new CameraDataAdapter(mAppContext, R.color.photo_placeholder); 1303 mDataAdapter.setLocalDataListener(mLocalDataListener); 1304 1305 mPreloader = new Preloader<Integer, AsyncTask>(FILMSTRIP_PRELOAD_AHEAD_ITEMS, mDataAdapter, 1306 mDataAdapter); 1307 1308 mCameraAppUI.getFilmstripContentPanel().setFilmstripListener(mFilmstripListener); 1309 if (mSettingsManager.getBoolean(SettingsManager.SETTING_SHOULD_SHOW_REFOCUS_VIEWER_CLING)) { 1310 mCameraAppUI.setupClingForViewer(CameraAppUI.BottomPanel.VIEWER_REFOCUS); 1311 } 1312 1313 mLocationManager = new LocationManager(mAppContext); 1314 1315 mOrientationManager = new OrientationManagerImpl(this); 1316 mOrientationManager.addOnOrientationChangeListener(mMainHandler, this); 1317 1318 setModuleFromModeIndex(getModeIndex()); 1319 mCameraAppUI.prepareModuleUI(); 1320 mCurrentModule.init(this, isSecureCamera(), isCaptureIntent()); 1321 1322 if (!mSecureCamera) { 1323 mFilmstripController.setDataAdapter(mDataAdapter); 1324 if (!isCaptureIntent()) { 1325 mDataAdapter.requestLoad(new Callback<Void>() { 1326 @Override 1327 public void onCallback(Void result) { 1328 fillTemporarySessions(); 1329 } 1330 }); 1331 } 1332 } else { 1333 // Put a lock placeholder as the last image by setting its date to 1334 // 0. 1335 ImageView v = (ImageView) getLayoutInflater().inflate( 1336 R.layout.secure_album_placeholder, null); 1337 v.setTag(R.id.mediadata_tag_viewtype, LocalDataViewType.SECURE_ALBUM_PLACEHOLDER.ordinal()); 1338 v.setOnClickListener(new View.OnClickListener() { 1339 @Override 1340 public void onClick(View view) { 1341 UsageStatistics.instance().changeScreen(NavigationChange.Mode.GALLERY, 1342 NavigationChange.InteractionCause.BUTTON); 1343 startGallery(); 1344 finish(); 1345 } 1346 }); 1347 v.setContentDescription(getString(R.string.accessibility_unlock_to_camera)); 1348 mDataAdapter = new FixedLastDataAdapter( 1349 mAppContext, 1350 mDataAdapter, 1351 new SimpleViewData( 1352 v, 1353 LocalDataViewType.SECURE_ALBUM_PLACEHOLDER, 1354 v.getDrawable().getIntrinsicWidth(), 1355 v.getDrawable().getIntrinsicHeight(), 1356 0, 0)); 1357 // Flush out all the original data. 1358 mDataAdapter.flush(); 1359 mFilmstripController.setDataAdapter(mDataAdapter); 1360 } 1361 1362 setupNfcBeamPush(); 1363 1364 mLocalImagesObserver = new LocalMediaObserver(); 1365 mLocalVideosObserver = new LocalMediaObserver(); 1366 1367 getContentResolver().registerContentObserver( 1368 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true, 1369 mLocalImagesObserver); 1370 getContentResolver().registerContentObserver( 1371 MediaStore.Video.Media.EXTERNAL_CONTENT_URI, true, 1372 mLocalVideosObserver); 1373 if (FeedbackHelper.feedbackAvailable()) { 1374 mFeedbackHelper = new FeedbackHelper(mAppContext); 1375 } 1376 mMemoryManager = getServices().getMemoryManager(); 1377 1378 AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { 1379 @Override 1380 public void run() { 1381 HashMap memoryData = mMemoryManager.queryMemory(); 1382 UsageStatistics.instance().reportMemoryConsumed(memoryData, 1383 MemoryQuery.REPORT_LABEL_LAUNCH); 1384 } 1385 }); 1386 } 1387 1388 /** 1389 * Get the current mode index from the Intent or from persistent 1390 * settings. 1391 */ 1392 public int getModeIndex() { 1393 int modeIndex = -1; 1394 int photoIndex = getResources().getInteger(R.integer.camera_mode_photo); 1395 int videoIndex = getResources().getInteger(R.integer.camera_mode_video); 1396 int gcamIndex = getResources().getInteger(R.integer.camera_mode_gcam); 1397 if (MediaStore.INTENT_ACTION_VIDEO_CAMERA.equals(getIntent().getAction()) 1398 || MediaStore.ACTION_VIDEO_CAPTURE.equals(getIntent().getAction())) { 1399 modeIndex = videoIndex; 1400 } else if (MediaStore.ACTION_IMAGE_CAPTURE.equals(getIntent().getAction())) { 1401 // Capture intent. 1402 modeIndex = photoIndex; 1403 } else if (MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA.equals(getIntent().getAction()) 1404 ||MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(getIntent() 1405 .getAction()) 1406 || MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(getIntent().getAction())) { 1407 modeIndex = mSettingsManager.getInt( 1408 SettingsManager.SETTING_KEY_CAMERA_MODULE_LAST_USED_INDEX); 1409 1410 // For upgraders who have not seen the aspect ratio selection screen, 1411 // we need to drop them back in the photo module and have them select 1412 // aspect ratio. 1413 // TODO: Move this to SettingsManager as an upgrade procedure. 1414 if (!mSettingsManager.getBoolean(SettingsManager.SETTING_USER_SELECTED_ASPECT_RATIO)) { 1415 modeIndex = photoIndex; 1416 } 1417 } else { 1418 // If the activity has not been started using an explicit intent, 1419 // read the module index from the last time the user changed modes 1420 modeIndex = mSettingsManager.getInt(SettingsManager.SETTING_STARTUP_MODULE_INDEX); 1421 if ((modeIndex == gcamIndex && 1422 !GcamHelper.hasGcamCapture()) || modeIndex < 0) { 1423 modeIndex = photoIndex; 1424 } 1425 } 1426 return modeIndex; 1427 } 1428 1429 /** 1430 * Call this whenever the mode drawer or filmstrip change the visibility 1431 * state. 1432 */ 1433 private void updatePreviewVisibility() { 1434 if (mCurrentModule == null) { 1435 return; 1436 } 1437 1438 int visibility = getPreviewVisibility(); 1439 mCameraAppUI.onPreviewVisiblityChanged(visibility); 1440 updatePreviewRendering(visibility); 1441 mCurrentModule.onPreviewVisibilityChanged(visibility); 1442 } 1443 1444 private void updatePreviewRendering(int visibility) { 1445 if (visibility == ModuleController.VISIBILITY_HIDDEN) { 1446 mCameraAppUI.pausePreviewRendering(); 1447 } else { 1448 mCameraAppUI.resumePreviewRendering(); 1449 } 1450 } 1451 1452 private int getPreviewVisibility() { 1453 if (mFilmstripCoversPreview) { 1454 return ModuleController.VISIBILITY_HIDDEN; 1455 } else if (mModeListVisible){ 1456 return ModuleController.VISIBILITY_COVERED; 1457 } else { 1458 return ModuleController.VISIBILITY_VISIBLE; 1459 } 1460 } 1461 1462 private void setRotationAnimation() { 1463 int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE; 1464 rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE; 1465 Window win = getWindow(); 1466 WindowManager.LayoutParams winParams = win.getAttributes(); 1467 winParams.rotationAnimation = rotationAnimation; 1468 win.setAttributes(winParams); 1469 } 1470 1471 @Override 1472 public void onUserInteraction() { 1473 super.onUserInteraction(); 1474 if (!isFinishing()) { 1475 keepScreenOnForAWhile(); 1476 } 1477 } 1478 1479 @Override 1480 public boolean dispatchTouchEvent(MotionEvent ev) { 1481 boolean result = super.dispatchTouchEvent(ev); 1482 if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) { 1483 // Real deletion is postponed until the next user interaction after 1484 // the gesture that triggers deletion. Until real deletion is 1485 // performed, users can click the undo button to bring back the 1486 // image that they chose to delete. 1487 if (mPendingDeletion && !mIsUndoingDeletion) { 1488 performDeletion(); 1489 } 1490 } 1491 return result; 1492 } 1493 1494 @Override 1495 public void onPause() { 1496 CameraPerformanceTracker.onEvent(CameraPerformanceTracker.ACTIVITY_PAUSE); 1497 1498 /* 1499 * Save the last module index after all secure camera and icon launches, 1500 * not just on mode switches. 1501 * 1502 * Right now we exclude capture intents from this logic, because we also 1503 * ignore the cross-Activity recovery logic in onStart for capture intents. 1504 */ 1505 if (!isCaptureIntent()) { 1506 mSettingsManager.setInt(SettingsManager.SETTING_STARTUP_MODULE_INDEX, 1507 mCurrentModeIndex); 1508 } 1509 1510 mPaused = true; 1511 mPeekAnimationHandler = null; 1512 mPeekAnimationThread.quitSafely(); 1513 mPeekAnimationThread = null; 1514 1515 // Delete photos that are pending deletion 1516 performDeletion(); 1517 mCurrentModule.pause(); 1518 mOrientationManager.pause(); 1519 // Close the camera and wait for the operation done. 1520 mCameraController.closeCamera(true); 1521 mPanoramaViewHelper.onPause(); 1522 1523 mLocalImagesObserver.setForegroundChangeListener(null); 1524 mLocalImagesObserver.setActivityPaused(true); 1525 mLocalVideosObserver.setActivityPaused(true); 1526 mPreloader.cancelAllLoads(); 1527 resetScreenOn(); 1528 1529 UsageStatistics.instance().backgrounded(); 1530 1531 super.onPause(); 1532 } 1533 1534 @Override 1535 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 1536 if (requestCode == REQ_CODE_DONT_SWITCH_TO_PREVIEW) { 1537 mResetToPreviewOnResume = false; 1538 } else { 1539 super.onActivityResult(requestCode, resultCode, data); 1540 } 1541 } 1542 1543 @Override 1544 public void onResume() { 1545 CameraPerformanceTracker.onEvent(CameraPerformanceTracker.ACTIVITY_RESUME); 1546 Log.v(TAG, "Build info: " + Build.DISPLAY); 1547 1548 mPaused = false; 1549 updateStorageSpaceAndHint(null); 1550 1551 mLastLayoutOrientation = getResources().getConfiguration().orientation; 1552 1553 // TODO: Handle this in OrientationManager. 1554 // Auto-rotate off 1555 if (Settings.System.getInt(getContentResolver(), 1556 Settings.System.ACCELEROMETER_ROTATION, 0) == 0) { 1557 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); 1558 mAutoRotateScreen = false; 1559 } else { 1560 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); 1561 mAutoRotateScreen = true; 1562 } 1563 1564 String action = getIntent().getAction(); 1565 // Foreground event logging 1566 if (MediaStore.ACTION_VIDEO_CAPTURE.equals(action)) { 1567 UsageStatistics.instance().foregrounded(ForegroundSource.ACTION_VIDEO_CAPTURE, 1568 currentUserInterfaceMode()); 1569 } else if (MediaStore.ACTION_IMAGE_CAPTURE.equals(action)) { 1570 UsageStatistics.instance().foregrounded(ForegroundSource.ACTION_IMAGE_CAPTURE, 1571 currentUserInterfaceMode()); 1572 } else if (MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(action) || 1573 INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action)) { 1574 // logged in onCreate() 1575 } else if (Intent.ACTION_MAIN.equals(action)) { 1576 UsageStatistics.instance().foregrounded(ForegroundSource.ACTION_MAIN, 1577 currentUserInterfaceMode()); 1578 } else { 1579 UsageStatistics.instance().foregrounded(ForegroundSource.UNKNOWN_SOURCE, 1580 currentUserInterfaceMode()); 1581 } 1582 1583 Drawable galleryLogo; 1584 if (mSecureCamera) { 1585 mGalleryIntent = null; 1586 galleryLogo = null; 1587 } else { 1588 mGalleryIntent = IntentHelper.getDefaultGalleryIntent(mAppContext); 1589 galleryLogo = IntentHelper.getGalleryIcon(mAppContext, mGalleryIntent); 1590 } 1591 if (galleryLogo == null) { 1592 try { 1593 galleryLogo = getPackageManager().getActivityLogo(getComponentName()); 1594 } catch (PackageManager.NameNotFoundException e) { 1595 Log.e(TAG, "Can't get the activity logo"); 1596 } 1597 } 1598 if (mGalleryIntent != null) { 1599 mActionBar.setDisplayUseLogoEnabled(true); 1600 } 1601 mActionBar.setLogo(galleryLogo); 1602 mOrientationManager.resume(); 1603 super.onResume(); 1604 mPeekAnimationThread = new HandlerThread("Peek animation"); 1605 mPeekAnimationThread.start(); 1606 mPeekAnimationHandler = new PeekAnimationHandler(mPeekAnimationThread.getLooper()); 1607 1608 mCurrentModule.hardResetSettings(mSettingsManager); 1609 mCurrentModule.resume(); 1610 UsageStatistics.instance().changeScreen(currentUserInterfaceMode(), 1611 NavigationChange.InteractionCause.BUTTON); 1612 setSwipingEnabled(true); 1613 1614 if (!mResetToPreviewOnResume) { 1615 LocalData data = mDataAdapter.getLocalData(mFilmstripController.getCurrentId()); 1616 if (data != null) { 1617 mDataAdapter.refresh(data.getUri()); 1618 } 1619 } 1620 // The share button might be disabled to avoid double tapping. 1621 mCameraAppUI.getFilmstripBottomControls().setShareEnabled(true); 1622 // Default is showing the preview, unless disabled by explicitly 1623 // starting an activity we want to return from to the filmstrip rather 1624 // than the preview. 1625 mResetToPreviewOnResume = true; 1626 1627 if (mLocalVideosObserver.isMediaDataChangedDuringPause() 1628 || mLocalImagesObserver.isMediaDataChangedDuringPause()) { 1629 if (!mSecureCamera) { 1630 // If it's secure camera, requestLoad() should not be called 1631 // as it will load all the data. 1632 if (!mFilmstripVisible) { 1633 mDataAdapter.requestLoad(new Callback<Void>() { 1634 @Override 1635 public void onCallback(Void result) { 1636 fillTemporarySessions(); 1637 } 1638 }); 1639 } else { 1640 mDataAdapter.requestLoadNewPhotos(); 1641 } 1642 } 1643 } 1644 mLocalImagesObserver.setActivityPaused(false); 1645 mLocalVideosObserver.setActivityPaused(false); 1646 if (!mSecureCamera) { 1647 mLocalImagesObserver.setForegroundChangeListener( 1648 new LocalMediaObserver.ChangeListener() { 1649 @Override 1650 public void onChange() { 1651 mDataAdapter.requestLoadNewPhotos(); 1652 } 1653 }); 1654 } 1655 1656 keepScreenOnForAWhile(); 1657 1658 // Lights-out mode at all times. 1659 final View rootView = findViewById(R.id.activity_root_view); 1660 mLightsOutRunnable.run(); 1661 getWindow().getDecorView().setOnSystemUiVisibilityChangeListener( 1662 new OnSystemUiVisibilityChangeListener() { 1663 @Override 1664 public void onSystemUiVisibilityChange(int visibility) { 1665 mMainHandler.removeCallbacks(mLightsOutRunnable); 1666 mMainHandler.postDelayed(mLightsOutRunnable, LIGHTS_OUT_DELAY_MS); 1667 } 1668 }); 1669 1670 mPanoramaViewHelper.onResume(); 1671 ReleaseDialogHelper.showReleaseInfoDialogOnStart(this, mSettingsManager); 1672 syncLocationManagerSetting(); 1673 1674 final int previewVisibility = getPreviewVisibility(); 1675 updatePreviewRendering(previewVisibility); 1676 } 1677 1678 private void fillTemporarySessions() { 1679 if (mSecureCamera) { 1680 return; 1681 } 1682 // There might be sessions still in flight (processed by our service). 1683 // Make sure they're added to the filmstrip. 1684 getServices().getCaptureSessionManager().fillTemporarySession(mSessionListener); 1685 } 1686 1687 @Override 1688 public void onStart() { 1689 super.onStart(); 1690 mPanoramaViewHelper.onStart(); 1691 1692 /* 1693 * If we're starting after launching a different Activity (lockscreen), 1694 * we need to use the last mode used in the other Activity, and 1695 * not the old one from this Activity. 1696 * 1697 * This needs to happen before CameraAppUI.resume() in order to set the 1698 * mode cover icon to the actual last mode used. 1699 * 1700 * Right now we exclude capture intents from this logic. 1701 */ 1702 int modeIndex = getModeIndex(); 1703 if (!isCaptureIntent() && mCurrentModeIndex != modeIndex) { 1704 onModeSelected(modeIndex); 1705 } 1706 1707 if (mResetToPreviewOnResume) { 1708 mCameraAppUI.resume(); 1709 mResetToPreviewOnResume = false; 1710 } 1711 } 1712 1713 @Override 1714 protected void onStop() { 1715 mPanoramaViewHelper.onStop(); 1716 if (mFeedbackHelper != null) { 1717 mFeedbackHelper.stopFeedback(); 1718 } 1719 1720 mLocationManager.disconnect(); 1721 super.onStop(); 1722 } 1723 1724 @Override 1725 public void onDestroy() { 1726 if (mSecureCamera) { 1727 unregisterReceiver(mScreenOffReceiver); 1728 } 1729 mActionBar.removeOnMenuVisibilityListener(this); 1730 mSettingsManager.removeAllListeners(); 1731 mCameraController.removeCallbackReceiver(); 1732 getContentResolver().unregisterContentObserver(mLocalImagesObserver); 1733 getContentResolver().unregisterContentObserver(mLocalVideosObserver); 1734 getServices().getCaptureSessionManager().removeSessionListener(mSessionListener); 1735 mCameraAppUI.onDestroy(); 1736 mModeListView.setVisibilityChangedListener(null); 1737 mCameraController = null; 1738 mSettingsManager = null; 1739 mCameraAppUI = null; 1740 mOrientationManager = null; 1741 mButtonManager = null; 1742 CameraManagerFactory.recycle(); 1743 super.onDestroy(); 1744 } 1745 1746 @Override 1747 public void onConfigurationChanged(Configuration config) { 1748 super.onConfigurationChanged(config); 1749 Log.v(TAG, "onConfigurationChanged"); 1750 if (config.orientation == Configuration.ORIENTATION_UNDEFINED) { 1751 return; 1752 } 1753 1754 if (mLastLayoutOrientation != config.orientation) { 1755 mLastLayoutOrientation = config.orientation; 1756 mCurrentModule.onLayoutOrientationChanged( 1757 mLastLayoutOrientation == Configuration.ORIENTATION_LANDSCAPE); 1758 } 1759 } 1760 1761 @Override 1762 public boolean onKeyDown(int keyCode, KeyEvent event) { 1763 if (!mFilmstripVisible) { 1764 if (mCurrentModule.onKeyDown(keyCode, event)) { 1765 return true; 1766 } 1767 // Prevent software keyboard or voice search from showing up. 1768 if (keyCode == KeyEvent.KEYCODE_SEARCH 1769 || keyCode == KeyEvent.KEYCODE_MENU) { 1770 if (event.isLongPress()) { 1771 return true; 1772 } 1773 } 1774 } 1775 1776 return super.onKeyDown(keyCode, event); 1777 } 1778 1779 @Override 1780 public boolean onKeyUp(int keyCode, KeyEvent event) { 1781 if (!mFilmstripVisible) { 1782 // If a module is in the middle of capture, it should 1783 // consume the key event. 1784 if (mCurrentModule.onKeyUp(keyCode, event)) { 1785 return true; 1786 } else if (keyCode == KeyEvent.KEYCODE_MENU 1787 || keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { 1788 // Let the mode list view consume the event. 1789 mCameraAppUI.openModeList(); 1790 return true; 1791 } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { 1792 mCameraAppUI.showFilmstrip(); 1793 return true; 1794 } 1795 } else { 1796 if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { 1797 mFilmstripController.goToNextItem(); 1798 return true; 1799 } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { 1800 boolean wentToPrevious = mFilmstripController.goToPreviousItem(); 1801 if (!wentToPrevious) { 1802 // at beginning of filmstrip, hide and go back to preview 1803 mCameraAppUI.hideFilmstrip(); 1804 } 1805 return true; 1806 } 1807 } 1808 return super.onKeyUp(keyCode, event); 1809 } 1810 1811 @Override 1812 public void onBackPressed() { 1813 if (!mCameraAppUI.onBackPressed()) { 1814 if (!mCurrentModule.onBackPressed()) { 1815 super.onBackPressed(); 1816 } 1817 } 1818 } 1819 1820 @Override 1821 public boolean isAutoRotateScreen() { 1822 // TODO: Move to OrientationManager. 1823 return mAutoRotateScreen; 1824 } 1825 1826 @Override 1827 public boolean onCreateOptionsMenu(Menu menu) { 1828 MenuInflater inflater = getMenuInflater(); 1829 inflater.inflate(R.menu.filmstrip_menu, menu); 1830 mActionBarMenu = menu; 1831 return super.onCreateOptionsMenu(menu); 1832 } 1833 1834 protected long getStorageSpaceBytes() { 1835 synchronized (mStorageSpaceLock) { 1836 return mStorageSpaceBytes; 1837 } 1838 } 1839 1840 protected interface OnStorageUpdateDoneListener { 1841 public void onStorageUpdateDone(long bytes); 1842 } 1843 1844 protected void updateStorageSpaceAndHint(final OnStorageUpdateDoneListener callback) { 1845 /* 1846 * We execute disk operations on a background thread in order to 1847 * free up the UI thread. Synchronizing on the lock below ensures 1848 * that when getStorageSpaceBytes is called, the main thread waits 1849 * until this method has completed. 1850 * 1851 * However, .execute() does not ensure this execution block will be 1852 * run right away (.execute() schedules this AsyncTask for sometime 1853 * in the future. executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR) 1854 * tries to execute the task in parellel with other AsyncTasks, but 1855 * there's still no guarantee). 1856 * e.g. don't call this then immediately call getStorageSpaceBytes(). 1857 * Instead, pass in an OnStorageUpdateDoneListener. 1858 */ 1859 (new AsyncTask<Void, Void, Long>() { 1860 @Override 1861 protected Long doInBackground(Void ... arg) { 1862 synchronized (mStorageSpaceLock) { 1863 mStorageSpaceBytes = Storage.getAvailableSpace(); 1864 return mStorageSpaceBytes; 1865 } 1866 } 1867 1868 @Override 1869 protected void onPostExecute(Long bytes) { 1870 updateStorageHint(bytes); 1871 if (callback != null) { 1872 callback.onStorageUpdateDone(bytes); 1873 } 1874 } 1875 }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 1876 } 1877 1878 protected void updateStorageHint(long storageSpace) { 1879 String message = null; 1880 if (storageSpace == Storage.UNAVAILABLE) { 1881 message = getString(R.string.no_storage); 1882 } else if (storageSpace == Storage.PREPARING) { 1883 message = getString(R.string.preparing_sd); 1884 } else if (storageSpace == Storage.UNKNOWN_SIZE) { 1885 message = getString(R.string.access_sd_fail); 1886 } else if (storageSpace <= Storage.LOW_STORAGE_THRESHOLD_BYTES) { 1887 message = getString(R.string.spaceIsLow_content); 1888 } 1889 1890 if (message != null) { 1891 Log.w(TAG, "Storage warning: " + message); 1892 if (mStorageHint == null) { 1893 mStorageHint = OnScreenHint.makeText(CameraActivity.this, message); 1894 } else { 1895 mStorageHint.setText(message); 1896 } 1897 mStorageHint.show(); 1898 UsageStatistics.instance().storageWarning(storageSpace); 1899 } else if (mStorageHint != null) { 1900 mStorageHint.cancel(); 1901 mStorageHint = null; 1902 } 1903 } 1904 1905 protected void setResultEx(int resultCode) { 1906 mResultCodeForTesting = resultCode; 1907 setResult(resultCode); 1908 } 1909 1910 protected void setResultEx(int resultCode, Intent data) { 1911 mResultCodeForTesting = resultCode; 1912 mResultDataForTesting = data; 1913 setResult(resultCode, data); 1914 } 1915 1916 public int getResultCode() { 1917 return mResultCodeForTesting; 1918 } 1919 1920 public Intent getResultData() { 1921 return mResultDataForTesting; 1922 } 1923 1924 public boolean isSecureCamera() { 1925 return mSecureCamera; 1926 } 1927 1928 @Override 1929 public boolean isPaused() { 1930 return mPaused; 1931 } 1932 1933 @Override 1934 public int getPreferredChildModeIndex(int modeIndex) { 1935 if (modeIndex == getResources().getInteger(R.integer.camera_mode_photo)) { 1936 boolean hdrPlusOn = mSettingsManager.isHdrPlusOn(); 1937 if (hdrPlusOn && GcamHelper.hasGcamCapture()) { 1938 modeIndex = getResources().getInteger(R.integer.camera_mode_gcam); 1939 } 1940 } 1941 return modeIndex; 1942 } 1943 1944 @Override 1945 public void onModeSelected(int modeIndex) { 1946 if (mCurrentModeIndex == modeIndex) { 1947 return; 1948 } 1949 1950 CameraPerformanceTracker.onEvent(CameraPerformanceTracker.MODE_SWITCH_START); 1951 // Record last used camera mode for quick switching 1952 if (modeIndex == getResources().getInteger(R.integer.camera_mode_photo) 1953 || modeIndex == getResources().getInteger(R.integer.camera_mode_gcam)) { 1954 mSettingsManager.setInt(SettingsManager.SETTING_KEY_CAMERA_MODULE_LAST_USED_INDEX, 1955 modeIndex); 1956 } 1957 1958 closeModule(mCurrentModule); 1959 1960 // Select the correct module index from the mode switcher index. 1961 modeIndex = getPreferredChildModeIndex(modeIndex); 1962 setModuleFromModeIndex(modeIndex); 1963 1964 mCameraAppUI.resetBottomControls(mCurrentModule, modeIndex); 1965 mCameraAppUI.addShutterListener(mCurrentModule); 1966 mCameraAppUI.hideLetterboxing(); 1967 openModule(mCurrentModule); 1968 mCurrentModule.onOrientationChanged(mLastRawOrientation); 1969 // Store the module index so we can use it the next time the Camera 1970 // starts up. 1971 mSettingsManager.setInt(SettingsManager.SETTING_STARTUP_MODULE_INDEX, modeIndex); 1972 } 1973 1974 /** 1975 * Shows the settings dialog. 1976 */ 1977 @Override 1978 public void onSettingsSelected() { 1979 UsageStatistics.instance().controlUsed( 1980 eventprotos.ControlEvent.ControlType.OVERALL_SETTINGS); 1981 Intent intent = new Intent(this, CameraSettingsActivity.class); 1982 startActivity(intent); 1983 } 1984 1985 /** 1986 * Sets the mCurrentModuleIndex, creates a new module instance for the given 1987 * index an sets it as mCurrentModule. 1988 */ 1989 private void setModuleFromModeIndex(int modeIndex) { 1990 ModuleManagerImpl.ModuleAgent agent = mModuleManager.getModuleAgent(modeIndex); 1991 if (agent == null) { 1992 return; 1993 } 1994 if (!agent.requestAppForCamera()) { 1995 mCameraController.closeCamera(true); 1996 } 1997 mCurrentModeIndex = agent.getModuleId(); 1998 mCurrentModule = (CameraModule) agent.createModule(this); 1999 } 2000 2001 @Override 2002 public SettingsManager getSettingsManager() { 2003 return mSettingsManager; 2004 } 2005 2006 @Override 2007 public CameraServices getServices() { 2008 return (CameraServices) getApplication(); 2009 } 2010 2011 public List<String> getSupportedModeNames() { 2012 List<Integer> indices = mModuleManager.getSupportedModeIndexList(); 2013 List<String> supported = new ArrayList<String>(); 2014 2015 for (Integer modeIndex : indices) { 2016 String name = CameraUtil.getCameraModeText(modeIndex, mAppContext); 2017 if (name != null && !name.equals("")) { 2018 supported.add(name); 2019 } 2020 } 2021 return supported; 2022 } 2023 2024 @Override 2025 public ButtonManager getButtonManager() { 2026 if (mButtonManager == null) { 2027 mButtonManager = new ButtonManager(this); 2028 } 2029 return mButtonManager; 2030 } 2031 2032 /** 2033 * Creates an AlertDialog appropriate for choosing whether to enable 2034 * location on the first run of the app. 2035 */ 2036 public AlertDialog getFirstTimeLocationAlert() { 2037 AlertDialog.Builder builder = new AlertDialog.Builder(this); 2038 builder = SettingsUtil.getFirstTimeLocationAlertBuilder(builder, new Callback<Boolean>() { 2039 @Override 2040 public void onCallback(Boolean locationOn) { 2041 mSettingsManager.setLocation(locationOn, mLocationManager); 2042 } 2043 }); 2044 if (builder != null) { 2045 return builder.create(); 2046 } else { 2047 return null; 2048 } 2049 } 2050 2051 /** 2052 * Launches an ACTION_EDIT intent for the given local data item. If 2053 * 'withTinyPlanet' is set, this will show a disambig dialog first to let 2054 * the user start either the tiny planet editor or another photo edior. 2055 * 2056 * @param data The data item to edit. 2057 */ 2058 public void launchEditor(LocalData data) { 2059 Intent intent = new Intent(Intent.ACTION_EDIT) 2060 .setDataAndType(data.getUri(), data.getMimeType()) 2061 .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 2062 try { 2063 launchActivityByIntent(intent); 2064 } catch (ActivityNotFoundException e) { 2065 final String msgEditWith = getResources().getString(R.string.edit_with); 2066 launchActivityByIntent(Intent.createChooser(intent, msgEditWith)); 2067 } 2068 } 2069 2070 @Override 2071 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 2072 super.onCreateContextMenu(menu, v, menuInfo); 2073 2074 MenuInflater inflater = getMenuInflater(); 2075 inflater.inflate(R.menu.filmstrip_context_menu, menu); 2076 } 2077 2078 @Override 2079 public boolean onContextItemSelected(MenuItem item) { 2080 switch (item.getItemId()) { 2081 case R.id.tiny_planet_editor: 2082 mMyFilmstripBottomControlListener.onTinyPlanet(); 2083 return true; 2084 case R.id.photo_editor: 2085 mMyFilmstripBottomControlListener.onEdit(); 2086 return true; 2087 } 2088 return false; 2089 } 2090 2091 /** 2092 * Launch the tiny planet editor. 2093 * 2094 * @param data The data must be a 360 degree stereographically mapped 2095 * panoramic image. It will not be modified, instead a new item 2096 * with the result will be added to the filmstrip. 2097 */ 2098 public void launchTinyPlanetEditor(LocalData data) { 2099 TinyPlanetFragment fragment = new TinyPlanetFragment(); 2100 Bundle bundle = new Bundle(); 2101 bundle.putString(TinyPlanetFragment.ARGUMENT_URI, data.getUri().toString()); 2102 bundle.putString(TinyPlanetFragment.ARGUMENT_TITLE, data.getTitle()); 2103 fragment.setArguments(bundle); 2104 fragment.show(getFragmentManager(), "tiny_planet"); 2105 } 2106 2107 /** 2108 * Returns what UI mode (capture mode or filmstrip) we are in. 2109 * Returned number one of {@link com.google.common.logging.eventprotos.NavigationChange.Mode} 2110 */ 2111 private int currentUserInterfaceMode() { 2112 int mode = NavigationChange.Mode.UNKNOWN_MODE; 2113 if (mCurrentModeIndex == getResources().getInteger(R.integer.camera_mode_photo)) { 2114 mode = NavigationChange.Mode.PHOTO_CAPTURE; 2115 } 2116 if (mCurrentModeIndex == getResources().getInteger(R.integer.camera_mode_video)) { 2117 mode = NavigationChange.Mode.VIDEO_CAPTURE; 2118 } 2119 if (mCurrentModeIndex == getResources().getInteger(R.integer.camera_mode_refocus)) { 2120 mode = NavigationChange.Mode.LENS_BLUR; 2121 } 2122 if (mCurrentModeIndex == getResources().getInteger(R.integer.camera_mode_gcam)) { 2123 mode = NavigationChange.Mode.HDR_PLUS; 2124 } 2125 if (mCurrentModeIndex == getResources().getInteger(R.integer.camera_mode_photosphere)) { 2126 mode = NavigationChange.Mode.PHOTO_SPHERE; 2127 } 2128 if (mCurrentModeIndex == getResources().getInteger(R.integer.camera_mode_panorama)) { 2129 mode = NavigationChange.Mode.PANORAMA; 2130 } 2131 if (mFilmstripVisible) { 2132 mode = NavigationChange.Mode.FILMSTRIP; 2133 } 2134 return mode; 2135 } 2136 2137 private void openModule(CameraModule module) { 2138 module.init(this, isSecureCamera(), isCaptureIntent()); 2139 module.hardResetSettings(mSettingsManager); 2140 module.resume(); 2141 UsageStatistics.instance().changeScreen(currentUserInterfaceMode(), 2142 NavigationChange.InteractionCause.BUTTON); 2143 updatePreviewVisibility(); 2144 } 2145 2146 private void closeModule(CameraModule module) { 2147 module.pause(); 2148 mCameraAppUI.clearModuleUI(); 2149 } 2150 2151 private void performDeletion() { 2152 if (!mPendingDeletion) { 2153 return; 2154 } 2155 hideUndoDeletionBar(false); 2156 mDataAdapter.executeDeletion(); 2157 } 2158 2159 public void showUndoDeletionBar() { 2160 if (mPendingDeletion) { 2161 performDeletion(); 2162 } 2163 Log.v(TAG, "showing undo bar"); 2164 mPendingDeletion = true; 2165 if (mUndoDeletionBar == null) { 2166 ViewGroup v = (ViewGroup) getLayoutInflater().inflate(R.layout.undo_bar, 2167 mAboveFilmstripControlLayout, true); 2168 mUndoDeletionBar = (ViewGroup) v.findViewById(R.id.camera_undo_deletion_bar); 2169 View button = mUndoDeletionBar.findViewById(R.id.camera_undo_deletion_button); 2170 button.setOnClickListener(new View.OnClickListener() { 2171 @Override 2172 public void onClick(View view) { 2173 mDataAdapter.undoDataRemoval(); 2174 hideUndoDeletionBar(true); 2175 } 2176 }); 2177 // Setting undo bar clickable to avoid touch events going through 2178 // the bar to the buttons (eg. edit button, etc) underneath the bar. 2179 mUndoDeletionBar.setClickable(true); 2180 // When there is user interaction going on with the undo button, we 2181 // do not want to hide the undo bar. 2182 button.setOnTouchListener(new View.OnTouchListener() { 2183 @Override 2184 public boolean onTouch(View v, MotionEvent event) { 2185 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { 2186 mIsUndoingDeletion = true; 2187 } else if (event.getActionMasked() == MotionEvent.ACTION_UP) { 2188 mIsUndoingDeletion = false; 2189 } 2190 return false; 2191 } 2192 }); 2193 } 2194 mUndoDeletionBar.setAlpha(0f); 2195 mUndoDeletionBar.setVisibility(View.VISIBLE); 2196 mUndoDeletionBar.animate().setDuration(200).alpha(1f).setListener(null).start(); 2197 } 2198 2199 private void hideUndoDeletionBar(boolean withAnimation) { 2200 Log.v(TAG, "Hiding undo deletion bar"); 2201 mPendingDeletion = false; 2202 if (mUndoDeletionBar != null) { 2203 if (withAnimation) { 2204 mUndoDeletionBar.animate().setDuration(200).alpha(0f) 2205 .setListener(new Animator.AnimatorListener() { 2206 @Override 2207 public void onAnimationStart(Animator animation) { 2208 // Do nothing. 2209 } 2210 2211 @Override 2212 public void onAnimationEnd(Animator animation) { 2213 mUndoDeletionBar.setVisibility(View.GONE); 2214 } 2215 2216 @Override 2217 public void onAnimationCancel(Animator animation) { 2218 // Do nothing. 2219 } 2220 2221 @Override 2222 public void onAnimationRepeat(Animator animation) { 2223 // Do nothing. 2224 } 2225 }).start(); 2226 } else { 2227 mUndoDeletionBar.setVisibility(View.GONE); 2228 } 2229 } 2230 } 2231 2232 @Override 2233 public void onOrientationChanged(int orientation) { 2234 // We keep the last known orientation. So if the user first orient 2235 // the camera then point the camera to floor or sky, we still have 2236 // the correct orientation. 2237 if (orientation == OrientationManager.ORIENTATION_UNKNOWN) { 2238 return; 2239 } 2240 mLastRawOrientation = orientation; 2241 if (mCurrentModule != null) { 2242 mCurrentModule.onOrientationChanged(orientation); 2243 } 2244 } 2245 2246 /** 2247 * Enable/disable swipe-to-filmstrip. Will always disable swipe if in 2248 * capture intent. 2249 * 2250 * @param enable {@code true} to enable swipe. 2251 */ 2252 public void setSwipingEnabled(boolean enable) { 2253 // TODO: Bring back the functionality. 2254 if (isCaptureIntent()) { 2255 // lockPreview(true); 2256 } else { 2257 // lockPreview(!enable); 2258 } 2259 } 2260 2261 // Accessor methods for getting latency times used in performance testing 2262 public long getFirstPreviewTime() { 2263 if (mCurrentModule instanceof PhotoModule) { 2264 long coverHiddenTime = getCameraAppUI().getCoverHiddenTime(); 2265 if (coverHiddenTime != -1) { 2266 return coverHiddenTime - mOnCreateTime; 2267 } 2268 } 2269 return -1; 2270 } 2271 2272 public long getAutoFocusTime() { 2273 return (mCurrentModule instanceof PhotoModule) ? 2274 ((PhotoModule) mCurrentModule).mAutoFocusTime : -1; 2275 } 2276 2277 public long getShutterLag() { 2278 return (mCurrentModule instanceof PhotoModule) ? 2279 ((PhotoModule) mCurrentModule).mShutterLag : -1; 2280 } 2281 2282 public long getShutterToPictureDisplayedTime() { 2283 return (mCurrentModule instanceof PhotoModule) ? 2284 ((PhotoModule) mCurrentModule).mShutterToPictureDisplayedTime : -1; 2285 } 2286 2287 public long getPictureDisplayedToJpegCallbackTime() { 2288 return (mCurrentModule instanceof PhotoModule) ? 2289 ((PhotoModule) mCurrentModule).mPictureDisplayedToJpegCallbackTime : -1; 2290 } 2291 2292 public long getJpegCallbackFinishTime() { 2293 return (mCurrentModule instanceof PhotoModule) ? 2294 ((PhotoModule) mCurrentModule).mJpegCallbackFinishTime : -1; 2295 } 2296 2297 public long getCaptureStartTime() { 2298 return (mCurrentModule instanceof PhotoModule) ? 2299 ((PhotoModule) mCurrentModule).mCaptureStartTime : -1; 2300 } 2301 2302 public boolean isRecording() { 2303 return (mCurrentModule instanceof VideoModule) ? 2304 ((VideoModule) mCurrentModule).isRecording() : false; 2305 } 2306 2307 public CameraManager.CameraOpenCallback getCameraOpenErrorCallback() { 2308 return mCameraController; 2309 } 2310 2311 // For debugging purposes only. 2312 public CameraModule getCurrentModule() { 2313 return mCurrentModule; 2314 } 2315 2316 @Override 2317 public void showTutorial(AbstractTutorialOverlay tutorial) { 2318 mCameraAppUI.showTutorial(tutorial, getLayoutInflater()); 2319 } 2320 2321 /** 2322 * Reads the current location recording settings and passes it on to the 2323 * location manager. 2324 */ 2325 public void syncLocationManagerSetting() { 2326 mSettingsManager.syncLocationManager(mLocationManager); 2327 } 2328 2329 private void keepScreenOnForAWhile() { 2330 if (mKeepScreenOn) { 2331 return; 2332 } 2333 mMainHandler.removeMessages(MSG_CLEAR_SCREEN_ON_FLAG); 2334 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 2335 mMainHandler.sendEmptyMessageDelayed(MSG_CLEAR_SCREEN_ON_FLAG, SCREEN_DELAY_MS); 2336 } 2337 2338 private void resetScreenOn() { 2339 mKeepScreenOn = false; 2340 mMainHandler.removeMessages(MSG_CLEAR_SCREEN_ON_FLAG); 2341 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 2342 } 2343 2344 /** 2345 * @return {@code true} if the Gallery is launched successfully. 2346 */ 2347 private boolean startGallery() { 2348 if (mGalleryIntent == null) { 2349 return false; 2350 } 2351 try { 2352 UsageStatistics.instance().changeScreen(NavigationChange.Mode.GALLERY, 2353 NavigationChange.InteractionCause.BUTTON); 2354 Intent startGalleryIntent = new Intent(mGalleryIntent); 2355 int currentDataId = mFilmstripController.getCurrentId(); 2356 LocalData currentLocalData = mDataAdapter.getLocalData(currentDataId); 2357 if (currentLocalData != null) { 2358 GalleryHelper.setContentUri(startGalleryIntent, currentLocalData.getUri()); 2359 } 2360 launchActivityByIntent(startGalleryIntent); 2361 } catch (ActivityNotFoundException e) { 2362 Log.w(TAG, "Failed to launch gallery activity, closing"); 2363 } 2364 return false; 2365 } 2366 2367 private void setNfcBeamPushUriFromData(LocalData data) { 2368 final Uri uri = data.getUri(); 2369 if (uri != Uri.EMPTY) { 2370 mNfcPushUris[0] = uri; 2371 } else { 2372 mNfcPushUris[0] = null; 2373 } 2374 } 2375 2376 /** 2377 * Updates the visibility of the filmstrip bottom controls and action bar. 2378 */ 2379 private void updateUiByData(final int dataId) { 2380 final LocalData currentData = mDataAdapter.getLocalData(dataId); 2381 if (currentData == null) { 2382 Log.w(TAG, "Current data ID not found."); 2383 hideSessionProgress(); 2384 return; 2385 } 2386 updateActionBarMenu(currentData); 2387 2388 /* Bottom controls. */ 2389 updateBottomControlsByData(currentData); 2390 2391 if (isSecureCamera()) { 2392 // We cannot show buttons in secure camera since go to other 2393 // activities might create a security hole. 2394 mCameraAppUI.getFilmstripBottomControls().hideControls(); 2395 return; 2396 } 2397 2398 2399 setNfcBeamPushUriFromData(currentData); 2400 2401 if (!mDataAdapter.isMetadataUpdated(dataId)) { 2402 mDataAdapter.updateMetadata(dataId); 2403 } 2404 } 2405 2406 /** 2407 * Updates the bottom controls based on the data. 2408 */ 2409 private void updateBottomControlsByData(final LocalData currentData) { 2410 2411 final CameraAppUI.BottomPanel filmstripBottomPanel = 2412 mCameraAppUI.getFilmstripBottomControls(); 2413 filmstripBottomPanel.showControls(); 2414 filmstripBottomPanel.setEditButtonVisibility( 2415 currentData.isDataActionSupported(LocalData.DATA_ACTION_EDIT)); 2416 filmstripBottomPanel.setShareButtonVisibility( 2417 currentData.isDataActionSupported(LocalData.DATA_ACTION_SHARE)); 2418 filmstripBottomPanel.setDeleteButtonVisibility( 2419 currentData.isDataActionSupported(LocalData.DATA_ACTION_DELETE)); 2420 2421 /* Progress bar */ 2422 2423 Uri contentUri = currentData.getUri(); 2424 CaptureSessionManager sessionManager = getServices() 2425 .getCaptureSessionManager(); 2426 2427 if (sessionManager.hasErrorMessage(contentUri)) { 2428 showProcessError(sessionManager.getErrorMesage(contentUri)); 2429 } else { 2430 filmstripBottomPanel.hideProgressError(); 2431 CaptureSession session = sessionManager.getSession(contentUri); 2432 2433 if (session != null) { 2434 int sessionProgress = session.getProgress(); 2435 2436 if (sessionProgress < 0) { 2437 hideSessionProgress(); 2438 } else { 2439 CharSequence progressMessage = session.getProgressMessage(); 2440 showSessionProgress(progressMessage); 2441 updateSessionProgress(sessionProgress); 2442 } 2443 } else { 2444 hideSessionProgress(); 2445 } 2446 } 2447 2448 /* View button */ 2449 2450 // We need to add this to a separate DB. 2451 final int viewButtonVisibility; 2452 if (PanoramaMetadataLoader.isPanoramaAndUseViewer(currentData)) { 2453 viewButtonVisibility = CameraAppUI.BottomPanel.VIEWER_PHOTO_SPHERE; 2454 } else if (RgbzMetadataLoader.hasRGBZData(currentData)) { 2455 viewButtonVisibility = CameraAppUI.BottomPanel.VIEWER_REFOCUS; 2456 } else { 2457 viewButtonVisibility = CameraAppUI.BottomPanel.VIEWER_NONE; 2458 } 2459 2460 filmstripBottomPanel.setTinyPlanetEnabled( 2461 PanoramaMetadataLoader.isPanorama360(currentData)); 2462 filmstripBottomPanel.setViewerButtonVisibility(viewButtonVisibility); 2463 } 2464 2465 private class PeekAnimationHandler extends Handler { 2466 private class DataAndCallback { 2467 LocalData mData; 2468 com.android.camera.util.Callback<Bitmap> mCallback; 2469 2470 public DataAndCallback(LocalData data, com.android.camera.util.Callback<Bitmap> 2471 callback) { 2472 mData = data; 2473 mCallback = callback; 2474 } 2475 } 2476 2477 public PeekAnimationHandler(Looper looper) { 2478 super(looper); 2479 } 2480 2481 /** 2482 * Starts the animation decoding job and posts a {@code Runnable} back 2483 * when when the decoding is done. 2484 * 2485 * @param data The data item to decode the thumbnail for. 2486 * @param callback {@link com.android.camera.util.Callback} after the 2487 * decoding is done. 2488 */ 2489 public void startDecodingJob(final LocalData data, 2490 final com.android.camera.util.Callback<Bitmap> callback) { 2491 PeekAnimationHandler.this.obtainMessage(0 /** dummy integer **/, 2492 new DataAndCallback(data, callback)).sendToTarget(); 2493 } 2494 2495 @Override 2496 public void handleMessage(Message msg) { 2497 final LocalData data = ((DataAndCallback) msg.obj).mData; 2498 final com.android.camera.util.Callback<Bitmap> callback = 2499 ((DataAndCallback) msg.obj).mCallback; 2500 if (data == null || callback == null) { 2501 return; 2502 } 2503 2504 final Bitmap bitmap; 2505 switch (data.getLocalDataType()) { 2506 case LocalData.LOCAL_IN_PROGRESS_DATA: 2507 byte[] jpegData = Storage.getJpegForSession(data.getUri()); 2508 if (jpegData != null) { 2509 bitmap = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length); 2510 } else { 2511 bitmap = null; 2512 } 2513 break; 2514 2515 case LocalData.LOCAL_IMAGE: 2516 FileInputStream stream; 2517 try { 2518 stream = new FileInputStream(data.getPath()); 2519 } catch (FileNotFoundException e) { 2520 Log.e(TAG, "File not found:" + data.getPath()); 2521 return; 2522 } 2523 Point dim = CameraUtil.resizeToFill(data.getWidth(), data.getHeight(), 2524 data.getRotation(), mAboveFilmstripControlLayout.getWidth(), 2525 mAboveFilmstripControlLayout.getMeasuredHeight()); 2526 if (data.getRotation() % 180 != 0) { 2527 int dummy = dim.x; 2528 dim.x = dim.y; 2529 dim.y = dummy; 2530 } 2531 bitmap = LocalDataUtil 2532 .loadImageThumbnailFromStream(stream, data.getWidth(), data.getHeight(), 2533 (int) (dim.x * 0.7f), (int) (dim.y * 0.7), 2534 data.getRotation(), MAX_PEEK_BITMAP_PIXELS); 2535 break; 2536 2537 case LocalData.LOCAL_VIDEO: 2538 bitmap = LocalDataUtil.loadVideoThumbnail(data.getPath()); 2539 break; 2540 2541 default: 2542 bitmap = null; 2543 break; 2544 } 2545 2546 if (bitmap == null) { 2547 return; 2548 } 2549 2550 mMainHandler.post(new Runnable() { 2551 @Override 2552 public void run() { 2553 callback.onCallback(bitmap); 2554 } 2555 }); 2556 } 2557 } 2558 2559 private void showDetailsDialog(int dataId) { 2560 final LocalData data = mDataAdapter.getLocalData(dataId); 2561 if (data == null) { 2562 return; 2563 } 2564 MediaDetails details = data.getMediaDetails(getAndroidContext()); 2565 if (details == null) { 2566 return; 2567 } 2568 Dialog detailDialog = DetailsDialog.create(CameraActivity.this, details); 2569 detailDialog.show(); 2570 UsageStatistics.instance().mediaInteraction( 2571 fileNameFromDataID(dataId), MediaInteraction.InteractionType.DETAILS, 2572 NavigationChange.InteractionCause.BUTTON, fileAgeFromDataID(dataId)); 2573 } 2574 2575 /** 2576 * Show or hide action bar items depending on current data type. 2577 */ 2578 private void updateActionBarMenu(LocalData data) { 2579 if (mActionBarMenu == null) { 2580 return; 2581 } 2582 2583 MenuItem detailsMenuItem = mActionBarMenu.findItem(R.id.action_details); 2584 if (detailsMenuItem == null) { 2585 return; 2586 } 2587 2588 int type = data.getLocalDataType(); 2589 boolean showDetails = (type == LocalData.LOCAL_IMAGE) || (type == LocalData.LOCAL_VIDEO); 2590 detailsMenuItem.setVisible(showDetails); 2591 } 2592} 2593