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