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