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; |
Mangesh Ghiware | 30968d0 | 2013-10-02 14:38:12 -0700 | [diff] [blame] | 24 | import android.content.ActivityNotFoundException; |
Doris Liu | b84b973 | 2013-06-18 17:14:26 -0700 | [diff] [blame] | 25 | import android.content.BroadcastReceiver; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 26 | import android.content.ContentResolver; |
Michael Kolb | 0865018 | 2013-02-25 19:43:56 -0800 | [diff] [blame] | 27 | import android.content.Context; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 28 | import android.content.Intent; |
Doris Liu | b84b973 | 2013-06-18 17:14:26 -0700 | [diff] [blame] | 29 | import android.content.IntentFilter; |
Sascha Haeberling | 2654dd9 | 2013-08-28 15:28:57 -0700 | [diff] [blame] | 30 | import android.content.SharedPreferences; |
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; |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 35 | import android.graphics.Color; |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 36 | import android.graphics.Matrix; |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 37 | import android.graphics.SurfaceTexture; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 38 | import android.graphics.drawable.ColorDrawable; |
Angus Kong | 6c0c7f1 | 2014-01-15 14:40:27 -0800 | [diff] [blame] | 39 | import android.graphics.drawable.Drawable; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 40 | import android.net.Uri; |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 41 | import android.nfc.NfcAdapter; |
| 42 | import android.nfc.NfcAdapter.CreateBeamUrisCallback; |
| 43 | import android.nfc.NfcEvent; |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 44 | import android.os.Build; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 45 | import android.os.Bundle; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 46 | import android.os.Handler; |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 47 | import android.os.Looper; |
| 48 | import android.os.Message; |
Sascha Haeberling | 2654dd9 | 2013-08-28 15:28:57 -0700 | [diff] [blame] | 49 | import android.preference.PreferenceManager; |
Doris Liu | 2a7f44c | 2013-08-12 15:18:53 -0700 | [diff] [blame] | 50 | import android.provider.MediaStore; |
Doris Liu | 3cf565c | 2013-02-15 10:55:37 -0800 | [diff] [blame] | 51 | import android.provider.Settings; |
Doris Liu | 7cbecee | 2014-01-30 12:29:27 -0800 | [diff] [blame] | 52 | import android.util.CameraPerformanceTracker; |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 53 | import android.util.Log; |
Sascha Haeberling | e8959e7 | 2014-01-31 15:21:02 +0100 | [diff] [blame] | 54 | import android.view.ContextMenu; |
| 55 | import android.view.ContextMenu.ContextMenuInfo; |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 56 | import android.view.Gravity; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 57 | import android.view.KeyEvent; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 58 | import android.view.LayoutInflater; |
Sascha Haeberling | e8959e7 | 2014-01-31 15:21:02 +0100 | [diff] [blame] | 59 | import android.view.MenuInflater; |
ztenghui | 0353ca2 | 2013-08-13 13:53:16 -0700 | [diff] [blame] | 60 | import android.view.MenuItem; |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 61 | import android.view.MotionEvent; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 62 | import android.view.View; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 63 | import android.view.ViewGroup; |
Michael Kolb | 0865018 | 2013-02-25 19:43:56 -0800 | [diff] [blame] | 64 | import android.view.Window; |
| 65 | import android.view.WindowManager; |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 66 | import android.widget.FrameLayout; |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 67 | import android.widget.FrameLayout.LayoutParams; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 68 | import android.widget.ImageView; |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 69 | import android.widget.PopupWindow; |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 70 | import android.widget.ProgressBar; |
Mangesh Ghiware | cd2eeb0 | 2013-08-23 13:28:21 -0700 | [diff] [blame] | 71 | import android.widget.ShareActionProvider; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 72 | import android.widget.TextView; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 73 | |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 74 | import com.android.camera.app.AppController; |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 75 | import com.android.camera.app.CameraAppUI; |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 76 | import com.android.camera.app.CameraController; |
| 77 | import com.android.camera.app.CameraManager; |
| 78 | import com.android.camera.app.CameraManagerFactory; |
| 79 | import com.android.camera.app.CameraProvider; |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 80 | import com.android.camera.app.CameraServices; |
Kevin Gabayan | ffbc43c | 2013-12-09 11:41:50 -0800 | [diff] [blame] | 81 | import com.android.camera.app.LocationManager; |
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; |
Angus Kong | 3250987 | 2013-10-02 16:53:40 -0700 | [diff] [blame] | 87 | import com.android.camera.data.InProgressDataWrapper; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 88 | import com.android.camera.data.LocalData; |
Angus Kong | 8e5e4ee | 2013-07-30 11:36:00 -0700 | [diff] [blame] | 89 | import com.android.camera.data.LocalDataAdapter; |
ztenghui | 064d600 | 2013-09-05 15:47:58 -0700 | [diff] [blame] | 90 | import com.android.camera.data.LocalMediaObserver; |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 91 | import com.android.camera.data.PanoramaMetadataLoader; |
| 92 | import com.android.camera.data.RgbzMetadataLoader; |
Angus Kong | bd26069 | 2013-08-07 14:52:56 -0700 | [diff] [blame] | 93 | import com.android.camera.data.SimpleViewData; |
Angus Kong | 01054e9 | 2013-12-10 11:06:18 -0800 | [diff] [blame] | 94 | import com.android.camera.filmstrip.FilmstripContentPanel; |
Angus Kong | 6284815 | 2013-11-08 17:25:29 -0800 | [diff] [blame] | 95 | import com.android.camera.filmstrip.FilmstripController; |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 96 | import com.android.camera.module.ModuleController; |
Angus Kong | 612321f | 2013-11-18 16:17:43 -0800 | [diff] [blame] | 97 | import com.android.camera.module.ModulesInfo; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 98 | import com.android.camera.session.CaptureSessionManager; |
| 99 | import com.android.camera.session.CaptureSessionManager.SessionListener; |
| 100 | import com.android.camera.session.PlaceholderManager; |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 101 | import com.android.camera.settings.SettingsManager; |
| 102 | import com.android.camera.settings.SettingsManager.SettingsCapabilities; |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 103 | import com.android.camera.tinyplanet.TinyPlanetFragment; |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 104 | import com.android.camera.ui.MainActivityLayout; |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 105 | import com.android.camera.ui.ModeListView; |
Doris Liu | 06db742 | 2013-12-09 19:36:25 -0800 | [diff] [blame] | 106 | import com.android.camera.ui.PreviewStatusListener; |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 107 | import com.android.camera.ui.SettingsView; |
Sascha Haeberling | 88ef766 | 2013-08-15 17:19:22 -0700 | [diff] [blame] | 108 | import com.android.camera.util.ApiHelper; |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 109 | import com.android.camera.util.CameraUtil; |
Christian Wyglendowski | 6fe8c82 | 2013-11-26 14:16:04 -0800 | [diff] [blame] | 110 | import com.android.camera.util.FeedbackHelper; |
Alan Newberger | 80461c2 | 2014-02-03 15:03:26 -0800 | [diff] [blame] | 111 | import com.android.camera.util.GalleryHelper; |
Ruben Brunk | a9d66bd | 2013-09-06 11:56:32 -0700 | [diff] [blame] | 112 | import com.android.camera.util.GcamHelper; |
Alan Newberger | 761306f | 2013-10-30 12:51:21 -0700 | [diff] [blame] | 113 | import com.android.camera.util.IntentHelper; |
Sascha Haeberling | 88ef766 | 2013-08-15 17:19:22 -0700 | [diff] [blame] | 114 | import com.android.camera.util.PhotoSphereHelper.PanoramaViewHelper; |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 115 | import com.android.camera.util.UsageStatistics; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 116 | import com.android.camera.widget.FilmstripView; |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 117 | import com.android.camera2.R; |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 118 | import com.google.common.logging.eventprotos; |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 119 | import com.google.common.logging.eventprotos.CameraEvent.InteractionCause; |
Sascha Haeberling | e8959e7 | 2014-01-31 15:21:02 +0100 | [diff] [blame] | 120 | import com.google.common.logging.eventprotos.NavigationChange; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 121 | |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 122 | import java.io.File; |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 123 | import java.lang.ref.WeakReference; |
Erin Dahlgren | f63967a | 2014-01-02 13:57:43 -0800 | [diff] [blame] | 124 | import java.util.ArrayList; |
Sascha Haeberling | 8793eff | 2014-01-15 16:33:59 -0800 | [diff] [blame] | 125 | import java.util.List; |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 126 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 127 | public class CameraActivity extends Activity |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 128 | implements AppController, CameraManager.CameraOpenCallback, |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 129 | ActionBar.OnMenuVisibilityListener, ShareActionProvider.OnShareTargetSelectedListener, |
| 130 | OrientationManager.OnOrientationChangeListener { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 131 | |
Sascha Haeberling | 5850115 | 2014-01-06 11:02:35 -0800 | [diff] [blame] | 132 | private static final String TAG = "CameraActivity"; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 133 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 134 | private static final String INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE = |
| 135 | "android.media.action.STILL_IMAGE_CAMERA_SECURE"; |
| 136 | public static final String ACTION_IMAGE_CAPTURE_SECURE = |
| 137 | "android.media.action.IMAGE_CAPTURE_SECURE"; |
| 138 | |
| 139 | // The intent extra for camera from secure lock screen. True if the gallery |
| 140 | // should only show newly captured pictures. sSecureAlbumId does not |
| 141 | // increment. This is used when switching between camera, camcorder, and |
| 142 | // panorama. If the extra is not set, it is in the normal camera mode. |
| 143 | public static final String SECURE_CAMERA_EXTRA = "secure_camera"; |
| 144 | |
Sascha Haeberling | b7639c6 | 2013-09-09 14:42:43 -0700 | [diff] [blame] | 145 | /** |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 146 | * Request code from an activity we started that indicated that we do not |
| 147 | * want to reset the view to the preview in onResume. |
Sascha Haeberling | b7639c6 | 2013-09-09 14:42:43 -0700 | [diff] [blame] | 148 | */ |
| 149 | public static final int REQ_CODE_DONT_SWITCH_TO_PREVIEW = 142; |
| 150 | |
Ruben Brunk | d217ed0 | 2013-10-08 23:31:13 -0700 | [diff] [blame] | 151 | public static final int REQ_CODE_GCAM_DEBUG_POSTCAPTURE = 999; |
| 152 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 153 | private static final int MSG_HIDE_ACTION_BAR = 1; |
| 154 | private static final int MSG_CLEAR_SCREEN_ON_FLAG = 2; |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 155 | private static final long SCREEN_DELAY_MS = 2 * 60 * 1000; // 2 mins. |
| 156 | |
| 157 | /** Should be used wherever a context is needed. */ |
| 158 | private Context mAppContext; |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 159 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 160 | /** |
| 161 | * Whether onResume should reset the view to the preview. |
| 162 | */ |
Sascha Haeberling | b7639c6 | 2013-09-09 14:42:43 -0700 | [diff] [blame] | 163 | private boolean mResetToPreviewOnResume = true; |
| 164 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 165 | /** |
| 166 | * This data adapter is used by FilmStripView. |
| 167 | */ |
Angus Kong | 8e5e4ee | 2013-07-30 11:36:00 -0700 | [diff] [blame] | 168 | private LocalDataAdapter mDataAdapter; |
Angus Kong | 8e5e4ee | 2013-07-30 11:36:00 -0700 | [diff] [blame] | 169 | |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 170 | /** |
| 171 | * TODO: This should be moved to the app level. |
| 172 | */ |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 173 | private SettingsManager mSettingsManager; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * TODO: This should be moved to the app level. |
| 177 | */ |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 178 | private SettingsController mSettingsController; |
Doris Liu | 70576b6 | 2013-11-14 20:30:33 -0800 | [diff] [blame] | 179 | private ModeListView mModeListView; |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 180 | private int mCurrentModeIndex; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 181 | private CameraModule mCurrentModule; |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 182 | private ModuleManagerImpl mModuleManager; |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 183 | private FrameLayout mAboveFilmstripControlLayout; |
Angus Kong | 6284815 | 2013-11-08 17:25:29 -0800 | [diff] [blame] | 184 | private FilmstripController mFilmstripController; |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 185 | private boolean mFilmstripVisible; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 186 | private TextView mBottomProgressText; |
| 187 | private ProgressBar mBottomProgressBar; |
| 188 | private View mSessionProgressPanel; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 189 | private int mResultCodeForTesting; |
| 190 | private Intent mResultDataForTesting; |
| 191 | private OnScreenHint mStorageHint; |
Angus Kong | 2dcc0a9 | 2013-09-25 13:00:08 -0700 | [diff] [blame] | 192 | private long mStorageSpaceBytes = Storage.LOW_STORAGE_THRESHOLD_BYTES; |
Doris Liu | 3cf565c | 2013-02-15 10:55:37 -0800 | [diff] [blame] | 193 | private boolean mAutoRotateScreen; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 194 | private boolean mSecureCamera; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 195 | private int mLastRawOrientation; |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 196 | private OrientationManagerImpl mOrientationManager; |
Erin Dahlgren | 21c21a6 | 2013-11-19 16:37:38 -0800 | [diff] [blame] | 197 | private LocationManager mLocationManager; |
Erin Dahlgren | 8a2933b | 2013-12-06 12:07:33 -0800 | [diff] [blame] | 198 | private ButtonManager mButtonManager; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 199 | private Handler mMainHandler; |
Sascha Haeberling | f1f5186 | 2013-07-31 11:28:21 -0700 | [diff] [blame] | 200 | private PanoramaViewHelper mPanoramaViewHelper; |
ztenghui | fa9e2cc | 2013-08-09 17:37:15 -0700 | [diff] [blame] | 201 | private ActionBar mActionBar; |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 202 | private ViewGroup mUndoDeletionBar; |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 203 | private boolean mIsUndoingDeletion = false; |
Doris Liu | 3cf565c | 2013-02-15 10:55:37 -0800 | [diff] [blame] | 204 | |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 205 | private final Uri[] mNfcPushUris = new Uri[1]; |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 206 | |
ztenghui | 064d600 | 2013-09-05 15:47:58 -0700 | [diff] [blame] | 207 | private LocalMediaObserver mLocalImagesObserver; |
| 208 | private LocalMediaObserver mLocalVideosObserver; |
Mangesh Ghiware | cd2eeb0 | 2013-08-23 13:28:21 -0700 | [diff] [blame] | 209 | |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 210 | private boolean mPendingDeletion = false; |
Sascha Haeberling | 5199c20 | 2013-09-05 17:10:19 -0700 | [diff] [blame] | 211 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 212 | private CameraController mCameraController; |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 213 | private boolean mPaused; |
Angus Kong | de3e438 | 2014-01-14 14:25:45 -0800 | [diff] [blame] | 214 | private boolean mUpAsGallery; |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 215 | private CameraAppUI mCameraAppUI; |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 216 | |
Christian Wyglendowski | 6fe8c82 | 2013-11-26 14:16:04 -0800 | [diff] [blame] | 217 | private FeedbackHelper mFeedbackHelper; |
Kevin Gabayan | a0e8347 | 2014-01-15 15:21:13 -0800 | [diff] [blame] | 218 | |
Angus Kong | 6c0c7f1 | 2014-01-15 14:40:27 -0800 | [diff] [blame] | 219 | private Intent mGalleryIntent; |
Kevin Gabayan | a0e8347 | 2014-01-15 15:21:13 -0800 | [diff] [blame] | 220 | private long mOnCreateTime; |
Christian Wyglendowski | 6fe8c82 | 2013-11-26 14:16:04 -0800 | [diff] [blame] | 221 | |
Spike Sprague | 0f3c4b4 | 2013-12-10 19:50:17 -0800 | [diff] [blame] | 222 | @Override |
| 223 | public CameraAppUI getCameraAppUI() { |
| 224 | return mCameraAppUI; |
| 225 | } |
| 226 | |
Doris Liu | b84b973 | 2013-06-18 17:14:26 -0700 | [diff] [blame] | 227 | // close activity when screen turns off |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 228 | private final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() { |
Doris Liu | b84b973 | 2013-06-18 17:14:26 -0700 | [diff] [blame] | 229 | @Override |
| 230 | public void onReceive(Context context, Intent intent) { |
| 231 | finish(); |
| 232 | } |
| 233 | }; |
| 234 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 235 | /** |
| 236 | * Whether the screen is kept turned on. |
| 237 | */ |
| 238 | private boolean mKeepScreenOn; |
Angus Kong | 53ae041 | 2013-12-01 23:21:49 -0800 | [diff] [blame] | 239 | private int mLastLayoutOrientation; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 240 | private final CameraAppUI.BottomControls.Listener mMyFilmstripBottomControlListener = |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 241 | new CameraAppUI.BottomControls.Listener() { |
| 242 | |
| 243 | /** |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 244 | * If the current photo is a photo sphere, this will launch the |
| 245 | * Photo Sphere panorama viewer. |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 246 | */ |
| 247 | @Override |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 248 | public void onExternalViewer() { |
| 249 | if (mPanoramaViewHelper == null) { |
| 250 | return; |
| 251 | } |
| 252 | final LocalData data = getCurrentLocalData(); |
| 253 | if (data == null) { |
| 254 | return; |
| 255 | } |
| 256 | final Uri contentUri = data.getContentUri(); |
| 257 | if (contentUri == Uri.EMPTY) { |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | if (PanoramaMetadataLoader.isPanorama(data)) { |
| 262 | mPanoramaViewHelper.showPanorama(contentUri); |
| 263 | } else if (RgbzMetadataLoader.hasRGBZData(data)) { |
| 264 | mPanoramaViewHelper.showRgbz(contentUri); |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public void onEdit() { |
| 270 | LocalData data = getCurrentLocalData(); |
| 271 | if (data == null) { |
| 272 | return; |
| 273 | } |
| 274 | launchEditor(data); |
| 275 | } |
| 276 | |
| 277 | @Override |
| 278 | public void onTinyPlanet() { |
| 279 | LocalData data = getCurrentLocalData(); |
| 280 | if (data == null) { |
| 281 | return; |
| 282 | } |
| 283 | launchTinyPlanetEditor(data); |
| 284 | } |
| 285 | |
Angus Kong | e0aff89 | 2013-12-11 20:51:01 -0800 | [diff] [blame] | 286 | @Override |
| 287 | public void onDelete() { |
| 288 | final int currentDataId = getCurrentDataId(); |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 289 | UsageStatistics.photoInteraction( |
| 290 | UsageStatistics.hashFileName(fileNameFromDataID(currentDataId)), |
| 291 | eventprotos.CameraEvent.InteractionType.DELETE, |
| 292 | InteractionCause.BUTTON); |
Angus Kong | e0aff89 | 2013-12-11 20:51:01 -0800 | [diff] [blame] | 293 | removeData(currentDataId); |
| 294 | } |
| 295 | |
| 296 | @Override |
| 297 | public void onShare() { |
Angus Kong | 662fbf4 | 2013-12-12 13:22:03 -0800 | [diff] [blame] | 298 | final LocalData data = getCurrentLocalData(); |
| 299 | Intent shareIntent = getShareIntentByData(data); |
| 300 | if (shareIntent != null) { |
Angus Kong | e4002f3 | 2013-12-13 22:24:11 -0800 | [diff] [blame] | 301 | try { |
Angus Kong | 0eaf016 | 2013-12-16 15:53:30 -0800 | [diff] [blame] | 302 | launchActivityByIntent(shareIntent); |
Angus Kong | e4002f3 | 2013-12-13 22:24:11 -0800 | [diff] [blame] | 303 | mCameraAppUI.getFilmstripBottomControls().setShareEnabled(false); |
| 304 | } catch (ActivityNotFoundException ex) { |
| 305 | // Nothing. |
| 306 | } |
Angus Kong | 662fbf4 | 2013-12-12 13:22:03 -0800 | [diff] [blame] | 307 | } |
Angus Kong | e0aff89 | 2013-12-11 20:51:01 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Angus Kong | e0aff89 | 2013-12-11 20:51:01 -0800 | [diff] [blame] | 310 | private int getCurrentDataId() { |
| 311 | return mFilmstripController.getCurrentId(); |
| 312 | } |
| 313 | |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 314 | private LocalData getCurrentLocalData() { |
Angus Kong | e0aff89 | 2013-12-11 20:51:01 -0800 | [diff] [blame] | 315 | return mDataAdapter.getLocalData(getCurrentDataId()); |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 316 | } |
Angus Kong | 662fbf4 | 2013-12-12 13:22:03 -0800 | [diff] [blame] | 317 | |
| 318 | /** |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 319 | * Sets up the share intent and NFC properly according to the |
| 320 | * data. |
Angus Kong | 662fbf4 | 2013-12-12 13:22:03 -0800 | [diff] [blame] | 321 | * |
| 322 | * @param data The data to be shared. |
| 323 | */ |
| 324 | private Intent getShareIntentByData(final LocalData data) { |
| 325 | Intent intent = null; |
| 326 | final Uri contentUri = data.getContentUri(); |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 327 | if (PanoramaMetadataLoader.isPanorama360(data) && |
Angus Kong | 662fbf4 | 2013-12-12 13:22:03 -0800 | [diff] [blame] | 328 | data.getContentUri() != Uri.EMPTY) { |
| 329 | intent = new Intent(Intent.ACTION_SEND); |
| 330 | intent.setType("application/vnd.google.panorama360+jpg"); |
| 331 | intent.putExtra(Intent.EXTRA_STREAM, contentUri); |
| 332 | } else if (data.isDataActionSupported(LocalData.DATA_ACTION_SHARE)) { |
| 333 | final String mimeType = data.getMimeType(); |
| 334 | intent = getShareIntentFromType(mimeType); |
| 335 | if (intent != null) { |
| 336 | intent.putExtra(Intent.EXTRA_STREAM, contentUri); |
| 337 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
| 338 | } |
| 339 | } |
| 340 | return intent; |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * Get the share intent according to the mimeType |
| 345 | * |
| 346 | * @param mimeType The mimeType of current data. |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 347 | * @return the video/image's ShareIntent or null if mimeType is |
| 348 | * invalid. |
Angus Kong | 662fbf4 | 2013-12-12 13:22:03 -0800 | [diff] [blame] | 349 | */ |
| 350 | private Intent getShareIntentFromType(String mimeType) { |
| 351 | // Lazily create the intent object. |
| 352 | Intent intent = new Intent(Intent.ACTION_SEND); |
| 353 | if (mimeType.startsWith("video/")) { |
| 354 | intent.setType("video/*"); |
| 355 | } else { |
| 356 | if (mimeType.startsWith("image/")) { |
| 357 | intent.setType("image/*"); |
| 358 | } else { |
| 359 | Log.w(TAG, "unsupported mimeType " + mimeType); |
| 360 | } |
| 361 | } |
| 362 | return intent; |
| 363 | } |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 364 | }; |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 365 | |
Kevin Gabayan | ffbc43c | 2013-12-09 11:41:50 -0800 | [diff] [blame] | 366 | private ComboPreferences mPreferences; |
| 367 | private ContentResolver mContentResolver; |
| 368 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 369 | @Override |
| 370 | public void onCameraOpened(CameraManager.CameraProxy camera) { |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 371 | if (!mModuleManager.getModuleAgent(mCurrentModeIndex).requestAppForCamera()) { |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 372 | // We shouldn't be here. Just close the camera and leave. |
| 373 | camera.release(false); |
| 374 | throw new IllegalStateException("Camera opened but the module shouldn't be " + |
| 375 | "requesting"); |
| 376 | } |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 377 | if (mCurrentModule != null) { |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 378 | SettingsCapabilities capabilities = |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 379 | SettingsController.getSettingsCapabilities(camera); |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 380 | mSettingsManager.changeCamera(camera.getCameraId(), capabilities); |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 381 | mCurrentModule.onCameraAvailable(camera); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 382 | } |
Erin Dahlgren | 1648c36 | 2014-01-06 15:06:04 -0800 | [diff] [blame] | 383 | mCameraAppUI.onChangeCamera(); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | @Override |
| 387 | public void onCameraDisabled(int cameraId) { |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 388 | UsageStatistics.cameraFailure(eventprotos.CameraFailure.FailureReason.SECURITY); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 389 | |
| 390 | CameraUtil.showErrorAndFinish(this, R.string.camera_disabled); |
| 391 | } |
| 392 | |
| 393 | @Override |
| 394 | public void onDeviceOpenFailure(int cameraId) { |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 395 | UsageStatistics.cameraFailure(eventprotos.CameraFailure.FailureReason.OPEN_FAILURE); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 396 | |
| 397 | CameraUtil.showErrorAndFinish(this, R.string.cannot_connect_camera); |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public void onReconnectionFailure(CameraManager mgr) { |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 402 | UsageStatistics.cameraFailure(eventprotos.CameraFailure.FailureReason.RECONNECT_FAILURE); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 403 | |
| 404 | CameraUtil.showErrorAndFinish(this, R.string.cannot_connect_camera); |
| 405 | } |
| 406 | |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 407 | private static class MainHandler extends Handler { |
| 408 | final WeakReference<CameraActivity> mActivity; |
| 409 | public MainHandler(CameraActivity activity, Looper looper) { |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 410 | super(looper); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 411 | mActivity = new WeakReference<CameraActivity>(activity); |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | @Override |
| 415 | public void handleMessage(Message msg) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 416 | CameraActivity activity = mActivity.get(); |
| 417 | if (activity == null) { |
| 418 | return; |
| 419 | } |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 420 | switch (msg.what) { |
| 421 | case MSG_HIDE_ACTION_BAR: { |
| 422 | removeMessages(MSG_HIDE_ACTION_BAR); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 423 | mActivity.get().setFilmstripUiVisibility(false); |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 424 | break; |
| 425 | } |
| 426 | |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 427 | case MSG_CLEAR_SCREEN_ON_FLAG: { |
| 428 | if (!mActivity.get().mPaused) { |
| 429 | mActivity.get().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 430 | } |
| 431 | break; |
| 432 | } |
| 433 | |
| 434 | default: |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 439 | private String fileNameFromDataID(int dataID) { |
| 440 | final LocalData localData = mDataAdapter.getLocalData(dataID); |
| 441 | |
| 442 | File localFile = new File(localData.getPath()); |
| 443 | return localFile.getName(); |
| 444 | } |
| 445 | |
Angus Kong | 01054e9 | 2013-12-10 11:06:18 -0800 | [diff] [blame] | 446 | private final FilmstripContentPanel.Listener mFilmstripListener = |
| 447 | new FilmstripContentPanel.Listener() { |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 448 | |
| 449 | @Override |
Erin Dahlgren | 3488188 | 2014-01-29 18:13:34 -0800 | [diff] [blame] | 450 | public void onSwipeOut() { |
| 451 | UsageStatistics.changeScreen(eventprotos.NavigationChange.Mode.PHOTO_CAPTURE, |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 452 | eventprotos.CameraEvent.InteractionCause.SWIPE_RIGHT); |
Erin Dahlgren | 3488188 | 2014-01-29 18:13:34 -0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | @Override |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 456 | public void onFilmstripHidden() { |
| 457 | mFilmstripVisible = false; |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 458 | CameraActivity.this.setFilmstripUiVisibility(false); |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 459 | // When the user hide the filmstrip (either swipe out or |
| 460 | // tap on back key) we move to the first item so next time |
| 461 | // when the user swipe in the filmstrip, the most recent |
| 462 | // one is shown. |
| 463 | mFilmstripController.goToFirstItem(); |
| 464 | if (mCurrentModule != null) { |
| 465 | mCurrentModule.onPreviewVisibilityChanged(true); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | @Override |
| 470 | public void onFilmstripShown() { |
| 471 | mFilmstripVisible = true; |
| 472 | updateUiByData(mFilmstripController.getCurrentId()); |
| 473 | if (mCurrentModule != null) { |
| 474 | mCurrentModule.onPreviewVisibilityChanged(false); |
| 475 | } |
| 476 | } |
| 477 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 478 | @Override |
| 479 | public void onDataPromoted(int dataID) { |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 480 | UsageStatistics.photoInteraction( |
| 481 | UsageStatistics.hashFileName(fileNameFromDataID(dataID)), |
| 482 | eventprotos.CameraEvent.InteractionType.DELETE, |
| 483 | InteractionCause.SWIPE_UP); |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 484 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 485 | removeData(dataID); |
| 486 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 487 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 488 | @Override |
| 489 | public void onDataDemoted(int dataID) { |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 490 | UsageStatistics.photoInteraction( |
| 491 | UsageStatistics.hashFileName(fileNameFromDataID(dataID)), |
| 492 | eventprotos.CameraEvent.InteractionType.DELETE, |
| 493 | InteractionCause.SWIPE_DOWN); |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 494 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 495 | removeData(dataID); |
| 496 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 497 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 498 | @Override |
Angus Kong | 4567160 | 2014-01-13 15:06:17 -0800 | [diff] [blame] | 499 | public void onEnterFullScreenUiShown(int dataId) { |
| 500 | if (mFilmstripVisible) { |
| 501 | CameraActivity.this.setFilmstripUiVisibility(true); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | @Override |
| 506 | public void onLeaveFullScreenUiShown(int dataId) { |
| 507 | // Do nothing. |
| 508 | } |
| 509 | |
| 510 | @Override |
| 511 | public void onEnterFullScreenUiHidden(int dataId) { |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 512 | if (mFilmstripVisible) { |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 513 | CameraActivity.this.setFilmstripUiVisibility(false); |
Erin Dahlgren | 3044d8c | 2013-10-10 18:23:45 -0700 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
| 517 | @Override |
Angus Kong | 4567160 | 2014-01-13 15:06:17 -0800 | [diff] [blame] | 518 | public void onLeaveFullScreenUiHidden(int dataId) { |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 519 | // Do nothing. |
| 520 | } |
Erin Dahlgren | 3044d8c | 2013-10-10 18:23:45 -0700 | [diff] [blame] | 521 | |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 522 | @Override |
| 523 | public void onEnterFilmstrip(int dataId) { |
Angus Kong | 6c0c7f1 | 2014-01-15 14:40:27 -0800 | [diff] [blame] | 524 | if (mGalleryIntent != null) { |
| 525 | mActionBar.setDisplayUseLogoEnabled(true); |
| 526 | mUpAsGallery = true; |
| 527 | } |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 528 | if (mFilmstripVisible) { |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 529 | CameraActivity.this.setFilmstripUiVisibility(true); |
Erin Dahlgren | 3044d8c | 2013-10-10 18:23:45 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | @Override |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 534 | public void onLeaveFilmstrip(int dataId) { |
Angus Kong | 6c0c7f1 | 2014-01-15 14:40:27 -0800 | [diff] [blame] | 535 | if (mGalleryIntent != null) { |
| 536 | mActionBar.setDisplayUseLogoEnabled(false); |
| 537 | mUpAsGallery = false; |
| 538 | } |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | @Override |
| 542 | public void onDataReloaded() { |
| 543 | if (!mFilmstripVisible) { |
| 544 | return; |
| 545 | } |
| 546 | updateUiByData(mFilmstripController.getCurrentId()); |
| 547 | } |
| 548 | |
| 549 | @Override |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 550 | public void onDataUpdated(int dataId) { |
| 551 | if (!mFilmstripVisible) { |
| 552 | return; |
| 553 | } |
| 554 | updateUiByData(mFilmstripController.getCurrentId()); |
| 555 | } |
| 556 | |
| 557 | @Override |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 558 | public void onEnterZoomView(int dataID) { |
| 559 | if (mFilmstripVisible) { |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 560 | CameraActivity.this.setFilmstripUiVisibility(false); |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
| 564 | @Override |
| 565 | public void onDataFocusChanged(final int prevDataId, final int newDataId) { |
| 566 | if (!mFilmstripVisible) { |
| 567 | return; |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 568 | } |
Angus Kong | 02cafdf | 2013-10-13 19:26:02 -0700 | [diff] [blame] | 569 | // TODO: This callback is UI event callback, should always |
| 570 | // happen on UI thread. Find the reason for this |
| 571 | // runOnUiThread() and fix it. |
Mangesh Ghiware | 33035c1 | 2013-08-23 13:28:21 -0700 | [diff] [blame] | 572 | runOnUiThread(new Runnable() { |
| 573 | @Override |
| 574 | public void run() { |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 575 | updateUiByData(newDataId); |
ztenghui | 2c3d9a5 | 2013-09-03 11:27:21 -0700 | [diff] [blame] | 576 | } |
Mangesh Ghiware | 33035c1 | 2013-08-23 13:28:21 -0700 | [diff] [blame] | 577 | }); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 578 | } |
| 579 | }; |
| 580 | |
Sascha Haeberling | 44c1afb | 2013-12-20 11:59:35 -0800 | [diff] [blame] | 581 | private final LocalDataAdapter.LocalDataListener mLocalDataListener = |
Angus Kong | e2f4c03 | 2013-12-19 10:24:33 -0800 | [diff] [blame] | 582 | new LocalDataAdapter.LocalDataListener() { |
| 583 | @Override |
| 584 | public void onMetadataUpdated(List<Integer> updatedData) { |
| 585 | int currentDataId = mFilmstripController.getCurrentId(); |
| 586 | for (Integer dataId : updatedData) { |
| 587 | if (dataId == currentDataId) { |
| 588 | updateBottomControlsByData(mDataAdapter.getLocalData(dataId)); |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | }; |
| 593 | |
Sascha Haeberling | 4ed2059 | 2013-09-13 11:58:33 -0700 | [diff] [blame] | 594 | public void gotoGallery() { |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 595 | UsageStatistics.changeScreen(NavigationChange.Mode.FILMSTRIP, |
| 596 | InteractionCause.BUTTON); |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 597 | |
Angus Kong | 6284815 | 2013-11-08 17:25:29 -0800 | [diff] [blame] | 598 | mFilmstripController.goToNextItem(); |
Sascha Haeberling | 4ed2059 | 2013-09-13 11:58:33 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Sascha Haeberling | 5199c20 | 2013-09-05 17:10:19 -0700 | [diff] [blame] | 601 | /** |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 602 | * If 'visible' is false, this hides the action bar and switches the |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 603 | * filmstrip UI to lights-out mode. |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 604 | * |
| 605 | * @param visible is false, this hides the action bar and switches the |
| 606 | * filmstrip UI to lights-out mode. |
Sascha Haeberling | 5199c20 | 2013-09-05 17:10:19 -0700 | [diff] [blame] | 607 | */ |
Doris Liu | 97cb1ea | 2013-10-11 16:54:51 -0700 | [diff] [blame] | 608 | // TODO: This should not be called outside of the activity. |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 609 | public void setFilmstripUiVisibility(boolean visible) { |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 610 | mMainHandler.removeMessages(MSG_HIDE_ACTION_BAR); |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 611 | |
ztenghui | 17f1e65 | 2013-11-06 14:20:31 -0800 | [diff] [blame] | 612 | int currentSystemUIVisibility = mAboveFilmstripControlLayout.getSystemUiVisibility(); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 613 | int newSystemUIVisibility = (visible ? View.SYSTEM_UI_FLAG_VISIBLE |
| 614 | : View.SYSTEM_UI_FLAG_FULLSCREEN); |
ztenghui | 17f1e65 | 2013-11-06 14:20:31 -0800 | [diff] [blame] | 615 | if (newSystemUIVisibility != currentSystemUIVisibility) { |
| 616 | mAboveFilmstripControlLayout.setSystemUiVisibility(newSystemUIVisibility); |
| 617 | } |
Doris Liu | 97cb1ea | 2013-10-11 16:54:51 -0700 | [diff] [blame] | 618 | |
ztenghui | 17f1e65 | 2013-11-06 14:20:31 -0800 | [diff] [blame] | 619 | boolean currentActionBarVisibility = mActionBar.isShowing(); |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 620 | mCameraAppUI.getFilmstripBottomControls().setVisible(visible); |
ztenghui | 17f1e65 | 2013-11-06 14:20:31 -0800 | [diff] [blame] | 621 | if (visible != currentActionBarVisibility) { |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 622 | if (visible) { |
| 623 | mActionBar.show(); |
| 624 | } else { |
| 625 | mActionBar.hide(); |
| 626 | } |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 627 | } |
Sascha Haeberling | 5199c20 | 2013-09-05 17:10:19 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 630 | private void hideSessionProgress() { |
| 631 | mSessionProgressPanel.setVisibility(View.GONE); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 634 | private void showSessionProgress(CharSequence message) { |
| 635 | mBottomProgressText.setText(message); |
| 636 | mSessionProgressPanel.setVisibility(View.VISIBLE); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 639 | private void updateSessionProgress(int progress) { |
| 640 | mBottomProgressBar.setProgress(progress); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 641 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 642 | |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 643 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN) |
| 644 | private void setupNfcBeamPush() { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 645 | NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mAppContext); |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 646 | if (adapter == null) { |
| 647 | return; |
| 648 | } |
| 649 | |
| 650 | if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS) { |
| 651 | // Disable beaming |
| 652 | adapter.setNdefPushMessage(null, CameraActivity.this); |
| 653 | return; |
| 654 | } |
| 655 | |
| 656 | adapter.setBeamPushUris(null, CameraActivity.this); |
| 657 | adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() { |
| 658 | @Override |
| 659 | public Uri[] createBeamUris(NfcEvent event) { |
| 660 | return mNfcPushUris; |
| 661 | } |
| 662 | }, CameraActivity.this); |
| 663 | } |
| 664 | |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 665 | @Override |
| 666 | public void onMenuVisibilityChanged(boolean isVisible) { |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 667 | // TODO: Remove this or bring back the original implementation: cancel |
| 668 | // auto-hide actionbar. |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 671 | @Override |
| 672 | public boolean onShareTargetSelected(ShareActionProvider shareActionProvider, Intent intent) { |
Angus Kong | 6284815 | 2013-11-08 17:25:29 -0800 | [diff] [blame] | 673 | int currentDataId = mFilmstripController.getCurrentId(); |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 674 | if (currentDataId < 0) { |
| 675 | return false; |
| 676 | } |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 677 | UsageStatistics.photoInteraction( |
| 678 | UsageStatistics.hashFileName(fileNameFromDataID(currentDataId)), |
| 679 | eventprotos.CameraEvent.InteractionType.SHARE, |
| 680 | InteractionCause.BUTTON); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 681 | // TODO add intent.getComponent().getPackageName() |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 682 | return true; |
| 683 | } |
| 684 | |
Sascha Haeberling | 14ff6c8 | 2013-12-13 13:29:58 -0800 | [diff] [blame] | 685 | // Note: All callbacks come back on the main thread. |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 686 | private final SessionListener mSessionListener = |
| 687 | new SessionListener() { |
Ruben Brunk | 7cfcafd | 2013-10-17 15:41:44 -0700 | [diff] [blame] | 688 | @Override |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 689 | public void onSessionQueued(final Uri uri) { |
Sascha Haeberling | 14ff6c8 | 2013-12-13 13:29:58 -0800 | [diff] [blame] | 690 | notifyNewMedia(uri); |
| 691 | int dataID = mDataAdapter.findDataByContentUri(uri); |
| 692 | if (dataID != -1) { |
| 693 | // Don't allow special UI actions (swipe to |
| 694 | // delete, for example) on in-progress data. |
| 695 | LocalData d = mDataAdapter.getLocalData(dataID); |
| 696 | InProgressDataWrapper newData = new InProgressDataWrapper(d); |
| 697 | mDataAdapter.updateData(dataID, newData); |
| 698 | } |
Angus Kong | 6798c34 | 2013-07-16 15:14:58 -0700 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | @Override |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 702 | public void onSessionDone(final Uri uri) { |
| 703 | Log.v(TAG, "onSessionDone:" + uri); |
Sascha Haeberling | 14ff6c8 | 2013-12-13 13:29:58 -0800 | [diff] [blame] | 704 | int doneID = mDataAdapter.findDataByContentUri(uri); |
| 705 | int currentDataId = mFilmstripController.getCurrentId(); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 706 | |
Sascha Haeberling | 14ff6c8 | 2013-12-13 13:29:58 -0800 | [diff] [blame] | 707 | if (currentDataId == doneID) { |
| 708 | hideSessionProgress(); |
| 709 | updateSessionProgress(0); |
| 710 | } |
Sascha Haeberling | 44c1afb | 2013-12-20 11:59:35 -0800 | [diff] [blame] | 711 | mDataAdapter.refresh(uri, /* isInProgress */ false); |
Angus Kong | 6798c34 | 2013-07-16 15:14:58 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | @Override |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 715 | public void onSessionProgress(final Uri uri, final int progress) { |
| 716 | if (progress < 0) { |
| 717 | // Do nothing, there is no task for this URI. |
| 718 | return; |
| 719 | } |
Sascha Haeberling | 14ff6c8 | 2013-12-13 13:29:58 -0800 | [diff] [blame] | 720 | int currentDataId = mFilmstripController.getCurrentId(); |
| 721 | if (currentDataId == -1) { |
| 722 | return; |
| 723 | } |
| 724 | if (uri.equals( |
| 725 | mDataAdapter.getLocalData(currentDataId).getContentUri())) { |
| 726 | updateSessionProgress(progress); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | @Override |
| 731 | public void onSessionUpdated(Uri uri) { |
Sascha Haeberling | 44c1afb | 2013-12-20 11:59:35 -0800 | [diff] [blame] | 732 | mDataAdapter.refresh(uri, /* isInProgress */ true); |
Angus Kong | 6798c34 | 2013-07-16 15:14:58 -0700 | [diff] [blame] | 733 | } |
| 734 | }; |
| 735 | |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 736 | @Override |
| 737 | public Context getAndroidContext() { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 738 | return mAppContext; |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | @Override |
Angus Kong | 0eaf016 | 2013-12-16 15:53:30 -0800 | [diff] [blame] | 742 | public void launchActivityByIntent(Intent intent) { |
| 743 | startActivityForResult(intent, REQ_CODE_DONT_SWITCH_TO_PREVIEW); |
| 744 | } |
| 745 | |
| 746 | @Override |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 747 | public int getCurrentModuleIndex() { |
| 748 | return mCurrentModeIndex; |
| 749 | } |
| 750 | |
| 751 | @Override |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 752 | public ModuleController getCurrentModuleController() { |
Sascha Haeberling | 8793eff | 2014-01-15 16:33:59 -0800 | [diff] [blame] | 753 | return mCurrentModule; |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | @Override |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 757 | public int getQuickSwitchToModuleId(int currentModuleIndex) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 758 | return mModuleManager.getQuickSwitchToModuleId(currentModuleIndex, mSettingsManager, |
| 759 | mAppContext); |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | @Override |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 763 | public SurfaceTexture getPreviewBuffer() { |
| 764 | // TODO: implement this |
| 765 | return null; |
| 766 | } |
| 767 | |
| 768 | @Override |
Doris Liu | 5a36754 | 2014-01-17 17:21:42 -0800 | [diff] [blame] | 769 | public void onPreviewReadyToStart() { |
| 770 | mCameraAppUI.onPreviewReadyToStart(); |
| 771 | } |
| 772 | |
| 773 | @Override |
Doris Liu | 2b906b8 | 2013-12-10 16:34:08 -0800 | [diff] [blame] | 774 | public void onPreviewStarted() { |
| 775 | mCameraAppUI.onPreviewStarted(); |
| 776 | } |
| 777 | |
| 778 | @Override |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 779 | public void addPreviewAreaSizeChangedListener( |
| 780 | PreviewStatusListener.PreviewAreaSizeChangedListener listener) { |
| 781 | mCameraAppUI.addPreviewAreaSizeChangedListener(listener); |
| 782 | } |
| 783 | |
| 784 | @Override |
| 785 | public void removePreviewAreaSizeChangedListener( |
| 786 | PreviewStatusListener.PreviewAreaSizeChangedListener listener) { |
| 787 | mCameraAppUI.removePreviewAreaSizeChangedListener(listener); |
| 788 | } |
| 789 | |
| 790 | @Override |
Doris Liu | 4d4a4bc | 2013-12-19 18:55:54 -0800 | [diff] [blame] | 791 | public void setupOneShotPreviewListener() { |
| 792 | mCameraController.setOneShotPreviewCallback(mMainHandler, |
| 793 | new CameraManager.CameraPreviewDataCallback() { |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 794 | @Override |
| 795 | public void onPreviewFrame(byte[] data, CameraManager.CameraProxy camera) { |
| 796 | mCameraAppUI.onNewPreviewFrame(); |
| 797 | } |
| 798 | }); |
Doris Liu | 4d4a4bc | 2013-12-19 18:55:54 -0800 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | @Override |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 802 | public void updatePreviewAspectRatio(float aspectRatio) { |
| 803 | mCameraAppUI.updatePreviewAspectRatio(aspectRatio); |
| 804 | } |
| 805 | |
| 806 | @Override |
Doris Liu | 2c559c4 | 2014-01-08 16:04:38 -0800 | [diff] [blame] | 807 | public boolean shouldShowShimmy() { |
| 808 | int remainingTimes = mSettingsManager.getInt( |
| 809 | SettingsManager.SETTING_SHIMMY_REMAINING_PLAY_TIMES_INDEX); |
| 810 | return remainingTimes > 0; |
| 811 | } |
| 812 | |
| 813 | @Override |
| 814 | public void decrementShimmyPlayTimes() { |
| 815 | int remainingTimes = mSettingsManager.getInt( |
| 816 | SettingsManager.SETTING_SHIMMY_REMAINING_PLAY_TIMES_INDEX) - 1; |
| 817 | if (remainingTimes >= 0) { |
| 818 | mSettingsManager.setInt(SettingsManager.SETTING_SHIMMY_REMAINING_PLAY_TIMES_INDEX, |
| 819 | remainingTimes); |
| 820 | } |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 821 | } |
Doris Liu | 2c559c4 | 2014-01-08 16:04:38 -0800 | [diff] [blame] | 822 | |
| 823 | @Override |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 824 | public void updatePreviewTransform(Matrix matrix) { |
| 825 | mCameraAppUI.updatePreviewTransform(matrix); |
| 826 | } |
| 827 | |
| 828 | @Override |
Doris Liu | 06db742 | 2013-12-09 19:36:25 -0800 | [diff] [blame] | 829 | public void setPreviewStatusListener(PreviewStatusListener previewStatusListener) { |
| 830 | mCameraAppUI.setPreviewStatusListener(previewStatusListener); |
| 831 | } |
| 832 | |
| 833 | @Override |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 834 | public FrameLayout getModuleLayoutRoot() { |
Doris Liu | c6c9740 | 2013-12-06 21:02:53 -0800 | [diff] [blame] | 835 | return mCameraAppUI.getModuleRootView(); |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | @Override |
| 839 | public void setShutterEventsListener(ShutterEventsListener listener) { |
| 840 | // TODO: implement this |
| 841 | } |
| 842 | |
| 843 | @Override |
| 844 | public void setShutterEnabled(boolean enabled) { |
| 845 | // TODO: implement this |
| 846 | } |
| 847 | |
| 848 | @Override |
| 849 | public boolean isShutterEnabled() { |
| 850 | // TODO: implement this |
| 851 | return false; |
| 852 | } |
| 853 | |
| 854 | @Override |
| 855 | public void startPreCaptureAnimation() { |
Doris Liu | 1dfe782 | 2013-12-12 00:02:08 -0800 | [diff] [blame] | 856 | mCameraAppUI.startPreCaptureAnimation(); |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | @Override |
| 860 | public void cancelPreCaptureAnimation() { |
| 861 | // TODO: implement this |
| 862 | } |
| 863 | |
| 864 | @Override |
| 865 | public void startPostCaptureAnimation() { |
| 866 | // TODO: implement this |
| 867 | } |
| 868 | |
| 869 | @Override |
| 870 | public void startPostCaptureAnimation(Bitmap thumbnail) { |
| 871 | // TODO: implement this |
| 872 | } |
| 873 | |
| 874 | @Override |
| 875 | public void cancelPostCaptureAnimation() { |
| 876 | // TODO: implement this |
| 877 | } |
| 878 | |
| 879 | @Override |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 880 | public OrientationManager getOrientationManager() { |
| 881 | return mOrientationManager; |
| 882 | } |
| 883 | |
| 884 | @Override |
| 885 | public LocationManager getLocationManager() { |
Erin Dahlgren | 21c21a6 | 2013-11-19 16:37:38 -0800 | [diff] [blame] | 886 | return mLocationManager; |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | @Override |
| 890 | public void lockOrientation() { |
| 891 | mOrientationManager.lockOrientation(); |
| 892 | } |
| 893 | |
| 894 | @Override |
| 895 | public void unlockOrientation() { |
| 896 | mOrientationManager.unlockOrientation(); |
| 897 | } |
| 898 | |
| 899 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 900 | public void notifyNewMedia(Uri uri) { |
| 901 | ContentResolver cr = getContentResolver(); |
| 902 | String mimeType = cr.getType(uri); |
| 903 | if (mimeType.startsWith("video/")) { |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 904 | sendBroadcast(new Intent(CameraUtil.ACTION_NEW_VIDEO, uri)); |
Sascha Haeberling | 44c1afb | 2013-12-20 11:59:35 -0800 | [diff] [blame] | 905 | mDataAdapter.addNewVideo(uri); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 906 | } else if (mimeType.startsWith("image/")) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 907 | CameraUtil.broadcastNewPicture(mAppContext, uri); |
Sascha Haeberling | 44c1afb | 2013-12-20 11:59:35 -0800 | [diff] [blame] | 908 | mDataAdapter.addNewPhoto(uri); |
Ruben Brunk | 7cfcafd | 2013-10-17 15:41:44 -0700 | [diff] [blame] | 909 | } else if (mimeType.startsWith(PlaceholderManager.PLACEHOLDER_MIME_TYPE)) { |
Sascha Haeberling | 44c1afb | 2013-12-20 11:59:35 -0800 | [diff] [blame] | 910 | mDataAdapter.addNewPhoto(uri); |
Doris Liu | 48239f4 | 2013-03-04 22:19:10 -0800 | [diff] [blame] | 911 | } else { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 912 | android.util.Log.w(TAG, "Unknown new media with MIME type:" |
| 913 | + mimeType + ", uri:" + uri); |
Doris Liu | 48239f4 | 2013-03-04 22:19:10 -0800 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 917 | @Override |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 918 | public void enableKeepScreenOn(boolean enabled) { |
| 919 | if (mPaused) { |
| 920 | return; |
| 921 | } |
| 922 | |
| 923 | mKeepScreenOn = enabled; |
| 924 | if (mKeepScreenOn) { |
| 925 | mMainHandler.removeMessages(MSG_CLEAR_SCREEN_ON_FLAG); |
| 926 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 927 | } else { |
| 928 | keepScreenOnForAWhile(); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | @Override |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 933 | public CameraProvider getCameraProvider() { |
| 934 | return mCameraController; |
| 935 | } |
| 936 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 937 | private void removeData(int dataID) { |
Sascha Haeberling | 44c1afb | 2013-12-20 11:59:35 -0800 | [diff] [blame] | 938 | mDataAdapter.removeData(dataID); |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 939 | if (mDataAdapter.getTotalNumber() > 1) { |
| 940 | showUndoDeletionBar(); |
| 941 | } else { |
| 942 | // If camera preview is the only view left in filmstrip, |
| 943 | // no need to show undo bar. |
Doris Liu | f2c1433 | 2013-09-26 11:24:37 -0700 | [diff] [blame] | 944 | mPendingDeletion = true; |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 945 | performDeletion(); |
Angus Kong | 1f9db2d | 2014-01-09 00:56:35 -0800 | [diff] [blame] | 946 | if (mFilmstripVisible) { |
| 947 | mCameraAppUI.getFilmstripContentPanel().animateHide(); |
| 948 | } |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 949 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 950 | } |
| 951 | |
ztenghui | 0353ca2 | 2013-08-13 13:53:16 -0700 | [diff] [blame] | 952 | @Override |
| 953 | public boolean onOptionsItemSelected(MenuItem item) { |
| 954 | // Handle presses on the action bar items |
| 955 | switch (item.getItemId()) { |
Alan Newberger | 3f969c1 | 2013-08-23 10:10:30 -0700 | [diff] [blame] | 956 | case android.R.id.home: |
Angus Kong | 6c0c7f1 | 2014-01-15 14:40:27 -0800 | [diff] [blame] | 957 | if (mFilmstripVisible && mUpAsGallery && startGallery()) { |
| 958 | return true; |
Emil Arfvidsson | f05962f | 2013-12-26 14:40:34 -0800 | [diff] [blame] | 959 | } |
Angus Kong | 6c0c7f1 | 2014-01-15 14:40:27 -0800 | [diff] [blame] | 960 | onBackPressed(); |
Angus Kong | 248f42b | 2013-12-06 15:49:17 -0800 | [diff] [blame] | 961 | return true; |
ztenghui | 0353ca2 | 2013-08-13 13:53:16 -0700 | [diff] [blame] | 962 | default: |
| 963 | return super.onOptionsItemSelected(item); |
| 964 | } |
| 965 | } |
| 966 | |
ztenghui | fd43e3b | 2013-09-03 11:30:11 -0700 | [diff] [blame] | 967 | private boolean isCaptureIntent() { |
| 968 | if (MediaStore.ACTION_VIDEO_CAPTURE.equals(getIntent().getAction()) |
| 969 | || MediaStore.ACTION_IMAGE_CAPTURE.equals(getIntent().getAction()) |
| 970 | || MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(getIntent().getAction())) { |
| 971 | return true; |
| 972 | } else { |
| 973 | return false; |
| 974 | } |
| 975 | } |
| 976 | |
ztenghui | 0353ca2 | 2013-08-13 13:53:16 -0700 | [diff] [blame] | 977 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 978 | public void onCreate(Bundle state) { |
| 979 | super.onCreate(state); |
Doris Liu | 7cbecee | 2014-01-30 12:29:27 -0800 | [diff] [blame] | 980 | CameraPerformanceTracker.onEvent(CameraPerformanceTracker.ACTIVITY_START); |
Kevin Gabayan | a0e8347 | 2014-01-15 15:21:13 -0800 | [diff] [blame] | 981 | mOnCreateTime = System.currentTimeMillis(); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 982 | mAppContext = getApplicationContext(); |
Sascha Haeberling | 048bf4d | 2013-10-06 17:49:51 -0700 | [diff] [blame] | 983 | GcamHelper.init(getContentResolver()); |
| 984 | |
ztenghui | 50df470 | 2013-08-13 15:53:57 -0700 | [diff] [blame] | 985 | getWindow().requestFeature(Window.FEATURE_ACTION_BAR); |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 986 | setContentView(R.layout.activity_main); |
ztenghui | fa9e2cc | 2013-08-09 17:37:15 -0700 | [diff] [blame] | 987 | mActionBar = getActionBar(); |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 988 | mActionBar.addOnMenuVisibilityListener(this); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 989 | mMainHandler = new MainHandler(this, getMainLooper()); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 990 | mCameraController = |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 991 | new CameraController(mAppContext, this, mMainHandler, |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 992 | CameraManagerFactory.getAndroidCameraManager()); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 993 | mPreferences = new ComboPreferences(mAppContext); |
Kevin Gabayan | ffbc43c | 2013-12-09 11:41:50 -0800 | [diff] [blame] | 994 | mContentResolver = this.getContentResolver(); |
Angus Kong | 40d95e9 | 2013-11-27 15:13:34 -0800 | [diff] [blame] | 995 | |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 996 | mSettingsManager = new SettingsManager(mAppContext, this, |
| 997 | mCameraController.getNumberOfCameras()); |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 998 | |
Angus Kong | 40d95e9 | 2013-11-27 15:13:34 -0800 | [diff] [blame] | 999 | // Remove this after we get rid of ComboPreferences. |
| 1000 | int cameraId = Integer.parseInt(mSettingsManager.get(SettingsManager.SETTING_CAMERA_ID)); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1001 | mPreferences.setLocalId(mAppContext, cameraId); |
Kevin Gabayan | ffbc43c | 2013-12-09 11:41:50 -0800 | [diff] [blame] | 1002 | CameraSettings.upgradeGlobalPreferences(mPreferences, |
| 1003 | mCameraController.getNumberOfCameras()); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1004 | // TODO: Try to move all the resources allocation to happen as soon as |
| 1005 | // possible so we can call module.init() at the earliest time. |
| 1006 | mModuleManager = new ModuleManagerImpl(); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1007 | ModulesInfo.setupModules(mAppContext, mModuleManager); |
ztenghui | fa9e2cc | 2013-08-09 17:37:15 -0700 | [diff] [blame] | 1008 | |
Doris Liu | 70576b6 | 2013-11-14 20:30:33 -0800 | [diff] [blame] | 1009 | mModeListView = (ModeListView) findViewById(R.id.mode_list_layout); |
Doris Liu | a20074f | 2013-12-09 15:19:06 -0800 | [diff] [blame] | 1010 | mModeListView.init(mModuleManager.getSupportedModeIndexList()); |
Michael Kolb | 0865018 | 2013-02-25 19:43:56 -0800 | [diff] [blame] | 1011 | if (ApiHelper.HAS_ROTATION_ANIMATION) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1012 | setRotationAnimation(); |
Michael Kolb | 0865018 | 2013-02-25 19:43:56 -0800 | [diff] [blame] | 1013 | } |
Doris Liu | aa87442 | 2013-09-18 19:43:12 -0700 | [diff] [blame] | 1014 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1015 | // Check if this is in the secure camera mode. |
| 1016 | Intent intent = getIntent(); |
| 1017 | String action = intent.getAction(); |
Doris Liu | b84b973 | 2013-06-18 17:14:26 -0700 | [diff] [blame] | 1018 | if (INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action) |
| 1019 | || ACTION_IMAGE_CAPTURE_SECURE.equals(action)) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1020 | mSecureCamera = true; |
| 1021 | } else { |
| 1022 | mSecureCamera = intent.getBooleanExtra(SECURE_CAMERA_EXTRA, false); |
| 1023 | } |
Doris Liu | b84b973 | 2013-06-18 17:14:26 -0700 | [diff] [blame] | 1024 | |
| 1025 | if (mSecureCamera) { |
Erin Dahlgren | f6edd53 | 2014-01-31 11:13:33 -0800 | [diff] [blame] | 1026 | // Foreground event caused by lock screen startup. |
| 1027 | // It is necessary to log this in onCreate, to avoid the |
| 1028 | // onResume->onPause->onResume sequence. |
| 1029 | UsageStatistics.foregrounded( |
| 1030 | eventprotos.ForegroundEvent.ForegroundSource.LOCK_SCREEN); |
| 1031 | |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1032 | // Change the window flags so that secure camera can show when |
| 1033 | // locked |
Doris Liu | b84b973 | 2013-06-18 17:14:26 -0700 | [diff] [blame] | 1034 | Window win = getWindow(); |
| 1035 | WindowManager.LayoutParams params = win.getAttributes(); |
| 1036 | params.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
| 1037 | win.setAttributes(params); |
| 1038 | |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1039 | // Filter for screen off so that we can finish secure camera |
| 1040 | // activity |
Doris Liu | b84b973 | 2013-06-18 17:14:26 -0700 | [diff] [blame] | 1041 | // when screen is off. |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1042 | IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); |
| 1043 | registerReceiver(mScreenOffReceiver, filter); |
Doris Liu | b84b973 | 2013-06-18 17:14:26 -0700 | [diff] [blame] | 1044 | } |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1045 | mCameraAppUI = new CameraAppUI(this, |
Sascha Haeberling | 8793eff | 2014-01-15 16:33:59 -0800 | [diff] [blame] | 1046 | (MainActivityLayout) findViewById(R.id.activity_root_view), isCaptureIntent()); |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1047 | |
| 1048 | mCameraAppUI.setFilmstripBottomControlsListener(mMyFilmstripBottomControlListener); |
| 1049 | |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 1050 | mAboveFilmstripControlLayout = |
Angus Kong | b95699e | 2013-12-07 13:52:51 -0800 | [diff] [blame] | 1051 | (FrameLayout) findViewById(R.id.camera_filmstrip_content_layout); |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1052 | |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1053 | // Add the session listener so we can track the session progress |
| 1054 | // updates. |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1055 | getServices().getCaptureSessionManager().addSessionListener(mSessionListener); |
| 1056 | mSessionProgressPanel = findViewById(R.id.pano_session_progress_panel); |
| 1057 | mBottomProgressBar = (ProgressBar) findViewById(R.id.pano_session_progress_bar); |
| 1058 | mBottomProgressText = (TextView) findViewById(R.id.pano_session_progress_text); |
Angus Kong | 6284815 | 2013-11-08 17:25:29 -0800 | [diff] [blame] | 1059 | mFilmstripController = ((FilmstripView) findViewById(R.id.filmstrip_view)).getController(); |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 1060 | mFilmstripController.setImageGap( |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1061 | getResources().getDimensionPixelSize(R.dimen.camera_film_strip_gap)); |
Sascha Haeberling | f1f5186 | 2013-07-31 11:28:21 -0700 | [diff] [blame] | 1062 | mPanoramaViewHelper = new PanoramaViewHelper(this); |
| 1063 | mPanoramaViewHelper.onCreate(); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1064 | // Set up the camera preview first so the preview shows up ASAP. |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1065 | mDataAdapter = new CameraDataAdapter(mAppContext, |
Angus Kong | 166e36f | 2013-12-03 08:54:42 -0800 | [diff] [blame] | 1066 | new ColorDrawable(getResources().getColor(R.color.photo_placeholder))); |
Angus Kong | e2f4c03 | 2013-12-19 10:24:33 -0800 | [diff] [blame] | 1067 | mDataAdapter.setLocalDataListener(mLocalDataListener); |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 1068 | |
Spike Sprague | 0f3c4b4 | 2013-12-10 19:50:17 -0800 | [diff] [blame] | 1069 | mCameraAppUI.getFilmstripContentPanel().setFilmstripListener(mFilmstripListener); |
Sascha Haeberling | 2654dd9 | 2013-08-28 15:28:57 -0700 | [diff] [blame] | 1070 | |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1071 | mLocationManager = new LocationManager(mAppContext); |
Erin Dahlgren | f63967a | 2014-01-02 13:57:43 -0800 | [diff] [blame] | 1072 | mSettingsController = new SettingsController(this); |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 1073 | |
| 1074 | int modeIndex = -1; |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1075 | int photoIndex = getResources().getInteger(R.integer.camera_mode_photo); |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 1076 | int videoIndex = getResources().getInteger(R.integer.camera_mode_video); |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1077 | int gcamIndex = getResources().getInteger(R.integer.camera_mode_gcam); |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 1078 | if (MediaStore.INTENT_ACTION_VIDEO_CAMERA.equals(getIntent().getAction()) |
| 1079 | || MediaStore.ACTION_VIDEO_CAPTURE.equals(getIntent().getAction())) { |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 1080 | modeIndex = videoIndex; |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 1081 | } else if (MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA.equals(getIntent().getAction()) |
| 1082 | || MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(getIntent() |
| 1083 | .getAction())) { |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1084 | modeIndex = photoIndex; |
Erin Dahlgren | 635a4b8 | 2013-11-25 15:21:18 -0800 | [diff] [blame] | 1085 | if (mSettingsManager.getInt(SettingsManager.SETTING_STARTUP_MODULE_INDEX) |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1086 | == gcamIndex && GcamHelper.hasGcamCapture()) { |
| 1087 | modeIndex = gcamIndex; |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 1088 | } |
| 1089 | } else if (MediaStore.ACTION_IMAGE_CAPTURE.equals(getIntent().getAction()) |
| 1090 | || MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(getIntent().getAction())) { |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1091 | modeIndex = photoIndex; |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 1092 | } else { |
| 1093 | // If the activity has not been started using an explicit intent, |
| 1094 | // read the module index from the last time the user changed modes |
Erin Dahlgren | 635a4b8 | 2013-11-25 15:21:18 -0800 | [diff] [blame] | 1095 | modeIndex = mSettingsManager.getInt(SettingsManager.SETTING_STARTUP_MODULE_INDEX); |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1096 | if ((modeIndex == gcamIndex && |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 1097 | !GcamHelper.hasGcamCapture()) || modeIndex < 0) { |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1098 | modeIndex = photoIndex; |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | mOrientationManager = new OrientationManagerImpl(this); |
| 1103 | mOrientationManager.addOnOrientationChangeListener(mMainHandler, this); |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1104 | |
| 1105 | setModuleFromModeIndex(modeIndex); |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 1106 | // TODO: Remove this when refactor is done. |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1107 | if (modeIndex == getResources().getInteger(R.integer.camera_mode_photo) |
| 1108 | || modeIndex == getResources().getInteger(R.integer.camera_mode_video) |
| 1109 | || modeIndex == getResources().getInteger(R.integer.camera_mode_gcam) |
| 1110 | || modeIndex == getResources().getInteger(R.integer.camera_mode_craft) |
| 1111 | || modeIndex == getResources().getInteger(R.integer.camera_mode_refocus)) { |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 1112 | mCameraAppUI.prepareModuleUI(); |
| 1113 | } |
Erin Dahlgren | cb99b3d | 2014-01-07 17:16:20 -0800 | [diff] [blame] | 1114 | |
Erin Dahlgren | 14466ba | 2014-02-03 14:01:54 -0800 | [diff] [blame] | 1115 | setBottomBarColor(); |
| 1116 | setBottomBarShutterIcon(); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1117 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1118 | mCurrentModule.init(this, isSecureCamera(), isCaptureIntent()); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1119 | |
| 1120 | if (!mSecureCamera) { |
Angus Kong | 6284815 | 2013-11-08 17:25:29 -0800 | [diff] [blame] | 1121 | mFilmstripController.setDataAdapter(mDataAdapter); |
Angus Kong | a719460 | 2013-09-06 17:20:15 -0700 | [diff] [blame] | 1122 | if (!isCaptureIntent()) { |
Sascha Haeberling | 44c1afb | 2013-12-20 11:59:35 -0800 | [diff] [blame] | 1123 | mDataAdapter.requestLoad(); |
Angus Kong | a719460 | 2013-09-06 17:20:15 -0700 | [diff] [blame] | 1124 | } |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1125 | } else { |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 1126 | // Put a lock placeholder as the last image by setting its date to |
| 1127 | // 0. |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1128 | ImageView v = (ImageView) getLayoutInflater().inflate( |
| 1129 | R.layout.secure_album_placeholder, null); |
Angus Kong | 690dc47 | 2013-09-21 14:48:51 -0700 | [diff] [blame] | 1130 | v.setOnClickListener(new View.OnClickListener() { |
| 1131 | @Override |
| 1132 | public void onClick(View view) { |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 1133 | UsageStatistics.changeScreen(NavigationChange.Mode.GALLERY, |
| 1134 | InteractionCause.BUTTON); |
Angus Kong | d3de171 | 2013-12-12 22:01:12 -0800 | [diff] [blame] | 1135 | startGallery(); |
Angus Kong | 690dc47 | 2013-09-21 14:48:51 -0700 | [diff] [blame] | 1136 | finish(); |
| 1137 | } |
| 1138 | }); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1139 | mDataAdapter = new FixedLastDataAdapter( |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1140 | mAppContext, |
Angus Kong | 166e36f | 2013-12-03 08:54:42 -0800 | [diff] [blame] | 1141 | mDataAdapter, |
Angus Kong | bd26069 | 2013-08-07 14:52:56 -0700 | [diff] [blame] | 1142 | new SimpleViewData( |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1143 | v, |
| 1144 | v.getDrawable().getIntrinsicWidth(), |
| 1145 | v.getDrawable().getIntrinsicHeight(), |
| 1146 | 0, 0)); |
| 1147 | // Flush out all the original data. |
| 1148 | mDataAdapter.flush(); |
Angus Kong | 6284815 | 2013-11-08 17:25:29 -0800 | [diff] [blame] | 1149 | mFilmstripController.setDataAdapter(mDataAdapter); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1150 | } |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 1151 | |
| 1152 | setupNfcBeamPush(); |
ztenghui | 064d600 | 2013-09-05 15:47:58 -0700 | [diff] [blame] | 1153 | |
Doris Liu | 2b86d87 | 2013-09-26 15:23:41 -0700 | [diff] [blame] | 1154 | mLocalImagesObserver = new LocalMediaObserver(); |
| 1155 | mLocalVideosObserver = new LocalMediaObserver(); |
ztenghui | 064d600 | 2013-09-05 15:47:58 -0700 | [diff] [blame] | 1156 | |
| 1157 | getContentResolver().registerContentObserver( |
| 1158 | MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true, |
| 1159 | mLocalImagesObserver); |
| 1160 | getContentResolver().registerContentObserver( |
| 1161 | MediaStore.Video.Media.EXTERNAL_CONTENT_URI, true, |
| 1162 | mLocalVideosObserver); |
Christian Wyglendowski | 6fe8c82 | 2013-11-26 14:16:04 -0800 | [diff] [blame] | 1163 | if (FeedbackHelper.feedbackAvailable()) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1164 | mFeedbackHelper = new FeedbackHelper(mAppContext); |
Christian Wyglendowski | 6fe8c82 | 2013-11-26 14:16:04 -0800 | [diff] [blame] | 1165 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1166 | } |
| 1167 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1168 | private void setRotationAnimation() { |
Michael Kolb | 0865018 | 2013-02-25 19:43:56 -0800 | [diff] [blame] | 1169 | int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1170 | rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE; |
Michael Kolb | 0865018 | 2013-02-25 19:43:56 -0800 | [diff] [blame] | 1171 | Window win = getWindow(); |
| 1172 | WindowManager.LayoutParams winParams = win.getAttributes(); |
| 1173 | winParams.rotationAnimation = rotationAnimation; |
| 1174 | win.setAttributes(winParams); |
| 1175 | } |
| 1176 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1177 | @Override |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1178 | public void onUserInteraction() { |
| 1179 | super.onUserInteraction(); |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1180 | if (!isFinishing()) { |
| 1181 | keepScreenOnForAWhile(); |
| 1182 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | @Override |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1186 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 1187 | boolean result = super.dispatchTouchEvent(ev); |
| 1188 | if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) { |
| 1189 | // Real deletion is postponed until the next user interaction after |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1190 | // the gesture that triggers deletion. Until real deletion is |
| 1191 | // performed, users can click the undo button to bring back the |
| 1192 | // image that they chose to delete. |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1193 | if (mPendingDeletion && !mIsUndoingDeletion) { |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1194 | performDeletion(); |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | return result; |
| 1198 | } |
| 1199 | |
| 1200 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1201 | public void onPause() { |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1202 | mPaused = true; |
Doris Liu | 7cbecee | 2014-01-30 12:29:27 -0800 | [diff] [blame] | 1203 | CameraPerformanceTracker.onEvent(CameraPerformanceTracker.ACTIVITY_PAUSE); |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1204 | |
Doris Liu | f2c1433 | 2013-09-26 11:24:37 -0700 | [diff] [blame] | 1205 | // Delete photos that are pending deletion |
| 1206 | performDeletion(); |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1207 | mCurrentModule.pause(); |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 1208 | mOrientationManager.pause(); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1209 | // Close the camera and wait for the operation done. |
| 1210 | mCameraController.closeCamera(); |
Alan Newberger | 04bd11c | 2014-01-28 18:09:30 -0800 | [diff] [blame] | 1211 | mPanoramaViewHelper.onPause(); |
Doris Liu | 2b86d87 | 2013-09-26 15:23:41 -0700 | [diff] [blame] | 1212 | |
| 1213 | mLocalImagesObserver.setActivityPaused(true); |
| 1214 | mLocalVideosObserver.setActivityPaused(true); |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1215 | resetScreenOn(); |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1216 | super.onPause(); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | @Override |
Sascha Haeberling | b7639c6 | 2013-09-09 14:42:43 -0700 | [diff] [blame] | 1220 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
ztenghui | 064d600 | 2013-09-05 15:47:58 -0700 | [diff] [blame] | 1221 | if (requestCode == REQ_CODE_DONT_SWITCH_TO_PREVIEW) { |
Sascha Haeberling | b7639c6 | 2013-09-09 14:42:43 -0700 | [diff] [blame] | 1222 | mResetToPreviewOnResume = false; |
| 1223 | } else { |
| 1224 | super.onActivityResult(requestCode, resultCode, data); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1229 | public void onResume() { |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1230 | mPaused = false; |
Doris Liu | 7cbecee | 2014-01-30 12:29:27 -0800 | [diff] [blame] | 1231 | CameraPerformanceTracker.onEvent(CameraPerformanceTracker.ACTIVITY_RESUME); |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1232 | |
Angus Kong | 53ae041 | 2013-12-01 23:21:49 -0800 | [diff] [blame] | 1233 | mLastLayoutOrientation = getResources().getConfiguration().orientation; |
| 1234 | |
Angus Kong | ce2b949 | 2013-09-05 17:49:06 -0700 | [diff] [blame] | 1235 | // TODO: Handle this in OrientationManager. |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 1236 | // Auto-rotate off |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1237 | if (Settings.System.getInt(getContentResolver(), |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 1238 | Settings.System.ACCELEROMETER_ROTATION, 0) == 0) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1239 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 1240 | mAutoRotateScreen = false; |
| 1241 | } else { |
| 1242 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); |
| 1243 | mAutoRotateScreen = true; |
| 1244 | } |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 1245 | |
Erin Dahlgren | f6edd53 | 2014-01-31 11:13:33 -0800 | [diff] [blame] | 1246 | if (isCaptureIntent()) { |
| 1247 | // Foreground event caused by photo or video capure intent. |
| 1248 | UsageStatistics.foregrounded( |
| 1249 | eventprotos.ForegroundEvent.ForegroundSource.INTENT_PICKER); |
| 1250 | } else if (!mSecureCamera) { |
| 1251 | // Foreground event that is not caused by an intent. |
| 1252 | UsageStatistics.foregrounded( |
| 1253 | eventprotos.ForegroundEvent.ForegroundSource.ICON_LAUNCHER); |
| 1254 | } |
Seth Raphael | cbd8267 | 2013-11-05 10:12:36 -0800 | [diff] [blame] | 1255 | |
Angus Kong | 6c0c7f1 | 2014-01-15 14:40:27 -0800 | [diff] [blame] | 1256 | Drawable galleryLogo; |
| 1257 | if (mSecureCamera) { |
| 1258 | mGalleryIntent = null; |
| 1259 | galleryLogo = null; |
| 1260 | } else { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1261 | mGalleryIntent = IntentHelper.getDefaultGalleryIntent(mAppContext); |
| 1262 | galleryLogo = IntentHelper.getGalleryIcon(mAppContext, mGalleryIntent); |
Angus Kong | 6c0c7f1 | 2014-01-15 14:40:27 -0800 | [diff] [blame] | 1263 | } |
| 1264 | if (galleryLogo == null) { |
| 1265 | try { |
| 1266 | galleryLogo = getPackageManager().getActivityLogo(getComponentName()); |
| 1267 | } catch (PackageManager.NameNotFoundException e) { |
| 1268 | Log.e(TAG, "Can't get the activity logo"); |
| 1269 | } |
| 1270 | } |
| 1271 | mActionBar.setLogo(galleryLogo); |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 1272 | mOrientationManager.resume(); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1273 | super.onResume(); |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1274 | mCurrentModule.resume(); |
Angus Kong | 6798c34 | 2013-07-16 15:14:58 -0700 | [diff] [blame] | 1275 | setSwipingEnabled(true); |
Sascha Haeberling | b7639c6 | 2013-09-09 14:42:43 -0700 | [diff] [blame] | 1276 | |
| 1277 | if (mResetToPreviewOnResume) { |
Doris Liu | 2b906b8 | 2013-12-10 16:34:08 -0800 | [diff] [blame] | 1278 | mCameraAppUI.resume(); |
Angus Kong | 2520b50 | 2014-01-10 17:45:27 -0800 | [diff] [blame] | 1279 | } else { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1280 | LocalData data = mDataAdapter.getLocalData(mFilmstripController.getCurrentId()); |
Angus Kong | 2520b50 | 2014-01-10 17:45:27 -0800 | [diff] [blame] | 1281 | if (data != null) { |
| 1282 | mDataAdapter.refresh(data.getContentUri(), false); |
| 1283 | } |
Sascha Haeberling | b7639c6 | 2013-09-09 14:42:43 -0700 | [diff] [blame] | 1284 | } |
Angus Kong | e4002f3 | 2013-12-13 22:24:11 -0800 | [diff] [blame] | 1285 | // The share button might be disabled to avoid double tapping. |
| 1286 | mCameraAppUI.getFilmstripBottomControls().setShareEnabled(true); |
Sascha Haeberling | b7639c6 | 2013-09-09 14:42:43 -0700 | [diff] [blame] | 1287 | // Default is showing the preview, unless disabled by explicitly |
| 1288 | // starting an activity we want to return from to the filmstrip rather |
| 1289 | // than the preview. |
| 1290 | mResetToPreviewOnResume = true; |
ztenghui | 064d600 | 2013-09-05 15:47:58 -0700 | [diff] [blame] | 1291 | |
Doris Liu | 2b86d87 | 2013-09-26 15:23:41 -0700 | [diff] [blame] | 1292 | if (mLocalVideosObserver.isMediaDataChangedDuringPause() |
| 1293 | || mLocalImagesObserver.isMediaDataChangedDuringPause()) { |
Angus Kong | 2d5c747 | 2013-10-12 23:48:46 -0700 | [diff] [blame] | 1294 | if (!mSecureCamera) { |
| 1295 | // If it's secure camera, requestLoad() should not be called |
| 1296 | // as it will load all the data. |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1297 | if (!mFilmstripVisible) { |
Sascha Haeberling | 44c1afb | 2013-12-20 11:59:35 -0800 | [diff] [blame] | 1298 | mDataAdapter.requestLoad(); |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1299 | } |
Angus Kong | 2d5c747 | 2013-10-12 23:48:46 -0700 | [diff] [blame] | 1300 | } |
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.setActivityPaused(false); |
| 1303 | mLocalVideosObserver.setActivityPaused(false); |
Doris Liu | 70576b6 | 2013-11-14 20:30:33 -0800 | [diff] [blame] | 1304 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1305 | keepScreenOnForAWhile(); |
Sascha Haeberling | 20639e7 | 2014-01-07 13:31:19 -0800 | [diff] [blame] | 1306 | |
| 1307 | // Lights-out mode at all times. |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1308 | findViewById(R.id.activity_root_view) |
| 1309 | .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); |
Alan Newberger | 04bd11c | 2014-01-28 18:09:30 -0800 | [diff] [blame] | 1310 | mPanoramaViewHelper.onResume(); |
Angus Kong | 6798c34 | 2013-07-16 15:14:58 -0700 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | @Override |
| 1314 | public void onStart() { |
| 1315 | super.onStart(); |
Sascha Haeberling | f1f5186 | 2013-07-31 11:28:21 -0700 | [diff] [blame] | 1316 | mPanoramaViewHelper.onStart(); |
Kevin Gabayan | ffbc43c | 2013-12-09 11:41:50 -0800 | [diff] [blame] | 1317 | boolean recordLocation = RecordLocationPreference.get( |
| 1318 | mPreferences, mContentResolver); |
| 1319 | mLocationManager.recordLocation(recordLocation); |
Sascha Haeberling | f1f5186 | 2013-07-31 11:28:21 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | @Override |
| 1323 | protected void onStop() { |
Sascha Haeberling | f1f5186 | 2013-07-31 11:28:21 -0700 | [diff] [blame] | 1324 | mPanoramaViewHelper.onStop(); |
Christian Wyglendowski | 6fe8c82 | 2013-11-26 14:16:04 -0800 | [diff] [blame] | 1325 | if (mFeedbackHelper != null) { |
| 1326 | mFeedbackHelper.stopFeedback(); |
| 1327 | } |
Angus Kong | 0e57fc1 | 2013-11-18 13:21:07 -0800 | [diff] [blame] | 1328 | |
Kevin Gabayan | ffbc43c | 2013-12-09 11:41:50 -0800 | [diff] [blame] | 1329 | mLocationManager.disconnect(); |
Angus Kong | 0e57fc1 | 2013-11-18 13:21:07 -0800 | [diff] [blame] | 1330 | CameraManagerFactory.recycle(); |
| 1331 | super.onStop(); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | @Override |
| 1335 | public void onDestroy() { |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 1336 | if (mSecureCamera) { |
| 1337 | unregisterReceiver(mScreenOffReceiver); |
| 1338 | } |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1339 | mActionBar.removeOnMenuVisibilityListener(this); |
Erin Dahlgren | 1648c36 | 2014-01-06 15:06:04 -0800 | [diff] [blame] | 1340 | mSettingsManager.removeAllListeners(); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1341 | mCameraController.removeCallbackReceiver(); |
ztenghui | 064d600 | 2013-09-05 15:47:58 -0700 | [diff] [blame] | 1342 | getContentResolver().unregisterContentObserver(mLocalImagesObserver); |
| 1343 | getContentResolver().unregisterContentObserver(mLocalVideosObserver); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1344 | getServices().getCaptureSessionManager().removeSessionListener(mSessionListener); |
| 1345 | mCameraAppUI.onDestroy(); |
| 1346 | mCameraController = null; |
| 1347 | mSettingsManager = null; |
| 1348 | mSettingsController = null; |
| 1349 | mCameraAppUI = null; |
| 1350 | mOrientationManager = null; |
| 1351 | mButtonManager = null; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1352 | super.onDestroy(); |
| 1353 | } |
| 1354 | |
| 1355 | @Override |
| 1356 | public void onConfigurationChanged(Configuration config) { |
| 1357 | super.onConfigurationChanged(config); |
Angus Kong | 166e36f | 2013-12-03 08:54:42 -0800 | [diff] [blame] | 1358 | Log.v(TAG, "onConfigurationChanged"); |
Angus Kong | 2f0e4a3 | 2013-12-03 10:02:35 -0800 | [diff] [blame] | 1359 | if (config.orientation == Configuration.ORIENTATION_UNDEFINED) { |
| 1360 | return; |
| 1361 | } |
| 1362 | |
Angus Kong | 53ae041 | 2013-12-01 23:21:49 -0800 | [diff] [blame] | 1363 | if (mLastLayoutOrientation != config.orientation) { |
| 1364 | mLastLayoutOrientation = config.orientation; |
Angus Kong | 2f0e4a3 | 2013-12-03 10:02:35 -0800 | [diff] [blame] | 1365 | mCurrentModule.onLayoutOrientationChanged( |
| 1366 | mLastLayoutOrientation == Configuration.ORIENTATION_LANDSCAPE); |
Angus Kong | 53ae041 | 2013-12-01 23:21:49 -0800 | [diff] [blame] | 1367 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | @Override |
| 1371 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Angus Kong | 8dcccb1 | 2014-01-02 16:00:49 -0800 | [diff] [blame] | 1372 | if (!mFilmstripVisible) { |
Doris Liu | dba16ae | 2013-10-03 15:31:40 -0700 | [diff] [blame] | 1373 | if (mCurrentModule.onKeyDown(keyCode, event)) { |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 1374 | return true; |
| 1375 | } |
Doris Liu | dba16ae | 2013-10-03 15:31:40 -0700 | [diff] [blame] | 1376 | // Prevent software keyboard or voice search from showing up. |
| 1377 | if (keyCode == KeyEvent.KEYCODE_SEARCH |
| 1378 | || keyCode == KeyEvent.KEYCODE_MENU) { |
| 1379 | if (event.isLongPress()) { |
| 1380 | return true; |
| 1381 | } |
| 1382 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1383 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1384 | |
| 1385 | return super.onKeyDown(keyCode, event); |
| 1386 | } |
| 1387 | |
| 1388 | @Override |
| 1389 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
Angus Kong | 8dcccb1 | 2014-01-02 16:00:49 -0800 | [diff] [blame] | 1390 | if (!mFilmstripVisible && mCurrentModule.onKeyUp(keyCode, event)) { |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 1391 | return true; |
| 1392 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1393 | return super.onKeyUp(keyCode, event); |
| 1394 | } |
| 1395 | |
Alan Newberger | 5f6b50d | 2013-08-30 15:19:48 -0700 | [diff] [blame] | 1396 | @Override |
| 1397 | public void onBackPressed() { |
Angus Kong | 166e36f | 2013-12-03 08:54:42 -0800 | [diff] [blame] | 1398 | if (!mCameraAppUI.onBackPressed()) { |
| 1399 | if (!mCurrentModule.onBackPressed()) { |
| 1400 | super.onBackPressed(); |
| 1401 | } |
Alan Newberger | 5f6b50d | 2013-08-30 15:19:48 -0700 | [diff] [blame] | 1402 | } |
| 1403 | } |
| 1404 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1405 | public boolean isAutoRotateScreen() { |
| 1406 | return mAutoRotateScreen; |
| 1407 | } |
| 1408 | |
| 1409 | protected void updateStorageSpace() { |
Angus Kong | 2dcc0a9 | 2013-09-25 13:00:08 -0700 | [diff] [blame] | 1410 | mStorageSpaceBytes = Storage.getAvailableSpace(); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Angus Kong | 2dcc0a9 | 2013-09-25 13:00:08 -0700 | [diff] [blame] | 1413 | protected long getStorageSpaceBytes() { |
| 1414 | return mStorageSpaceBytes; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | protected void updateStorageSpaceAndHint() { |
| 1418 | updateStorageSpace(); |
Angus Kong | 2dcc0a9 | 2013-09-25 13:00:08 -0700 | [diff] [blame] | 1419 | updateStorageHint(mStorageSpaceBytes); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | protected void updateStorageHint(long storageSpace) { |
| 1423 | String message = null; |
| 1424 | if (storageSpace == Storage.UNAVAILABLE) { |
| 1425 | message = getString(R.string.no_storage); |
| 1426 | } else if (storageSpace == Storage.PREPARING) { |
| 1427 | message = getString(R.string.preparing_sd); |
| 1428 | } else if (storageSpace == Storage.UNKNOWN_SIZE) { |
| 1429 | message = getString(R.string.access_sd_fail); |
Angus Kong | 2dcc0a9 | 2013-09-25 13:00:08 -0700 | [diff] [blame] | 1430 | } else if (storageSpace <= Storage.LOW_STORAGE_THRESHOLD_BYTES) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1431 | message = getString(R.string.spaceIsLow_content); |
| 1432 | } |
| 1433 | |
| 1434 | if (message != null) { |
| 1435 | if (mStorageHint == null) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1436 | mStorageHint = OnScreenHint.makeText(mAppContext, message); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1437 | } else { |
| 1438 | mStorageHint.setText(message); |
| 1439 | } |
| 1440 | mStorageHint.show(); |
| 1441 | } else if (mStorageHint != null) { |
| 1442 | mStorageHint.cancel(); |
| 1443 | mStorageHint = null; |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | protected void setResultEx(int resultCode) { |
| 1448 | mResultCodeForTesting = resultCode; |
| 1449 | setResult(resultCode); |
| 1450 | } |
| 1451 | |
| 1452 | protected void setResultEx(int resultCode, Intent data) { |
| 1453 | mResultCodeForTesting = resultCode; |
| 1454 | mResultDataForTesting = data; |
| 1455 | setResult(resultCode, data); |
| 1456 | } |
| 1457 | |
| 1458 | public int getResultCode() { |
| 1459 | return mResultCodeForTesting; |
| 1460 | } |
| 1461 | |
| 1462 | public Intent getResultData() { |
| 1463 | return mResultDataForTesting; |
| 1464 | } |
| 1465 | |
| 1466 | public boolean isSecureCamera() { |
| 1467 | return mSecureCamera; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | @Override |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1471 | public boolean isPaused() { |
| 1472 | return mPaused; |
| 1473 | } |
| 1474 | |
| 1475 | @Override |
| 1476 | public void onModeSelected(int modeIndex) { |
| 1477 | if (mCurrentModeIndex == modeIndex) { |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 1478 | return; |
| 1479 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1480 | |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1481 | int settingsIndex = getResources().getInteger(R.integer.camera_mode_setting); |
| 1482 | if (modeIndex == settingsIndex) { |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 1483 | onSettingsSelected(); |
| 1484 | return; |
| 1485 | } |
| 1486 | |
Doris Liu | 7cbecee | 2014-01-30 12:29:27 -0800 | [diff] [blame] | 1487 | CameraPerformanceTracker.onEvent(CameraPerformanceTracker.MODE_SWITCH_START); |
Doris Liu | cf8b653 | 2014-01-15 19:17:38 -0800 | [diff] [blame] | 1488 | // Record last used camera mode for quick switching |
| 1489 | if (modeIndex == getResources().getInteger(R.integer.camera_mode_photo) |
| 1490 | || modeIndex == getResources().getInteger(R.integer.camera_mode_craft)) { |
| 1491 | mSettingsManager.setInt(SettingsManager.SETTING_KEY_CAMERA_MODULE_LAST_USED_INDEX, |
| 1492 | modeIndex); |
| 1493 | } |
| 1494 | |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1495 | closeModule(mCurrentModule); |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 1496 | int oldModuleIndex = mCurrentModeIndex; |
Erin Dahlgren | a340f07 | 2014-01-06 17:31:23 -0800 | [diff] [blame] | 1497 | |
| 1498 | // Refocus and Gcam are modes that cannot be selected |
| 1499 | // from the mode list view, because they are not list items. |
| 1500 | // Check whether we should interpret MODULE_CRAFT as either. |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1501 | if (modeIndex == getResources().getInteger(R.integer.camera_mode_craft)) { |
Erin Dahlgren | a340f07 | 2014-01-06 17:31:23 -0800 | [diff] [blame] | 1502 | boolean refocusOn = mSettingsManager.isRefocusOn(); |
| 1503 | boolean hdrPlusOn = mSettingsManager.isHdrPlusOn(); |
| 1504 | if (refocusOn && hdrPlusOn) { |
| 1505 | throw new IllegalStateException("Refocus and hdr plus cannot be on together."); |
| 1506 | } |
| 1507 | if (refocusOn) { |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1508 | modeIndex = getResources().getInteger(R.integer.camera_mode_refocus); |
Erin Dahlgren | 481a3b3 | 2014-01-22 11:49:33 -0800 | [diff] [blame] | 1509 | } else if (hdrPlusOn && GcamHelper.hasGcamCapture()) { |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1510 | modeIndex = getResources().getInteger(R.integer.camera_mode_gcam); |
Erin Dahlgren | a340f07 | 2014-01-06 17:31:23 -0800 | [diff] [blame] | 1511 | } else { |
| 1512 | // Do nothing, keep MODULE_CRAFT. |
| 1513 | } |
| 1514 | } |
| 1515 | |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1516 | setModuleFromModeIndex(modeIndex); |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 1517 | |
Erin Dahlgren | 5f500be | 2013-12-10 14:53:35 -0800 | [diff] [blame] | 1518 | // TODO: The following check is temporary for modules attached to the |
| 1519 | // generic_module layout. When the refactor is done, similar logic will |
| 1520 | // be applied to all modules. |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1521 | if (mCurrentModeIndex == getResources().getInteger(R.integer.camera_mode_photo) |
| 1522 | || mCurrentModeIndex == getResources().getInteger(R.integer.camera_mode_video) |
| 1523 | || mCurrentModeIndex == getResources().getInteger(R.integer.camera_mode_gcam) |
| 1524 | || mCurrentModeIndex == getResources().getInteger(R.integer.camera_mode_craft) |
| 1525 | || mCurrentModeIndex == getResources().getInteger(R.integer.camera_mode_refocus)) { |
| 1526 | if (oldModuleIndex != getResources().getInteger(R.integer.camera_mode_photo) |
| 1527 | && oldModuleIndex != getResources().getInteger(R.integer.camera_mode_video) |
| 1528 | && oldModuleIndex != getResources().getInteger(R.integer.camera_mode_gcam) |
| 1529 | && oldModuleIndex != getResources().getInteger(R.integer.camera_mode_craft) |
| 1530 | && oldModuleIndex != getResources().getInteger(R.integer.camera_mode_refocus)) { |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 1531 | mCameraAppUI.prepareModuleUI(); |
| 1532 | } else { |
| 1533 | mCameraAppUI.clearModuleUI(); |
| 1534 | } |
| 1535 | } else { |
| 1536 | // This is the old way of removing all views in CameraRootView. Will |
| 1537 | // be deprecated soon. It is here to make sure modules that haven't |
| 1538 | // been refactored can still function. |
| 1539 | mCameraAppUI.clearCameraUI(); |
| 1540 | } |
| 1541 | |
Sascha Haeberling | 2654dd9 | 2013-08-28 15:28:57 -0700 | [diff] [blame] | 1542 | openModule(mCurrentModule); |
| 1543 | mCurrentModule.onOrientationChanged(mLastRawOrientation); |
Sascha Haeberling | 2654dd9 | 2013-08-28 15:28:57 -0700 | [diff] [blame] | 1544 | // Store the module index so we can use it the next time the Camera |
| 1545 | // starts up. |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1546 | SharedPreferences prefs = PreferenceManager |
| 1547 | .getDefaultSharedPreferences(mAppContext); |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1548 | prefs.edit().putInt(CameraSettings.KEY_STARTUP_MODULE_INDEX, modeIndex).apply(); |
| 1549 | } |
| 1550 | |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 1551 | public void onSettingsSelected() { |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1552 | // Temporary until we finalize the touch flow. |
| 1553 | LayoutInflater inflater = getLayoutInflater(); |
| 1554 | SettingsView settingsView = (SettingsView) inflater.inflate(R.layout.settings_list_layout, |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1555 | null, false); |
Erin Dahlgren | f63967a | 2014-01-02 13:57:43 -0800 | [diff] [blame] | 1556 | if (mSettingsController != null) { |
| 1557 | settingsView.setController(mSettingsController); |
| 1558 | } |
Christian Wyglendowski | 6fe8c82 | 2013-11-26 14:16:04 -0800 | [diff] [blame] | 1559 | if (mFeedbackHelper != null) { |
| 1560 | settingsView.setFeedbackHelper(mFeedbackHelper); |
| 1561 | } |
Erin Dahlgren | 4bb8082 | 2013-11-27 10:42:10 -0800 | [diff] [blame] | 1562 | PopupWindow popup = new PopupWindow(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1563 | popup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); |
| 1564 | popup.setOutsideTouchable(true); |
| 1565 | popup.setFocusable(true); |
| 1566 | popup.setContentView(settingsView); |
| 1567 | popup.showAtLocation(mModeListView.getRootView(), Gravity.CENTER, 0, 0); |
Sascha Haeberling | 2654dd9 | 2013-08-28 15:28:57 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | /** |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 1571 | * Sets the mCurrentModuleIndex, creates a new module instance for the given |
| 1572 | * index an sets it as mCurrentModule. |
Sascha Haeberling | 2654dd9 | 2013-08-28 15:28:57 -0700 | [diff] [blame] | 1573 | */ |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1574 | private void setModuleFromModeIndex(int modeIndex) { |
| 1575 | ModuleManagerImpl.ModuleAgent agent = mModuleManager.getModuleAgent(modeIndex); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1576 | if (agent == null) { |
| 1577 | return; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1578 | } |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1579 | if (!agent.requestAppForCamera()) { |
| 1580 | mCameraController.closeCamera(); |
| 1581 | } |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1582 | mCurrentModeIndex = agent.getModuleId(); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1583 | mCurrentModule = (CameraModule) agent.createModule(this); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1584 | } |
| 1585 | |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1586 | @Override |
| 1587 | public SettingsManager getSettingsManager() { |
| 1588 | return mSettingsManager; |
| 1589 | } |
| 1590 | |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1591 | @Override |
| 1592 | public CameraServices getServices() { |
| 1593 | return (CameraServices) getApplication(); |
| 1594 | } |
| 1595 | |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 1596 | @Override |
| 1597 | public SettingsController getSettingsController() { |
| 1598 | return mSettingsController; |
| 1599 | } |
| 1600 | |
Erin Dahlgren | f63967a | 2014-01-02 13:57:43 -0800 | [diff] [blame] | 1601 | public List<String> getSupportedModeNames() { |
| 1602 | List<Integer> indices = mModuleManager.getSupportedModeIndexList(); |
| 1603 | List<String> supported = new ArrayList<String>(); |
| 1604 | |
| 1605 | for (Integer modeIndex : indices) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1606 | String name = CameraUtil.getCameraModeText(modeIndex, mAppContext); |
Erin Dahlgren | f63967a | 2014-01-02 13:57:43 -0800 | [diff] [blame] | 1607 | if (name != null && !name.equals("")) { |
| 1608 | supported.add(name); |
| 1609 | } |
| 1610 | } |
| 1611 | return supported; |
| 1612 | } |
| 1613 | |
Erin Dahlgren | 1848494 | 2014-01-07 11:46:57 -0800 | [diff] [blame] | 1614 | @Override |
Erin Dahlgren | 18e2ef6 | 2013-12-05 14:53:38 -0800 | [diff] [blame] | 1615 | public ButtonManager getButtonManager() { |
Erin Dahlgren | 8a2933b | 2013-12-06 12:07:33 -0800 | [diff] [blame] | 1616 | if (mButtonManager == null) { |
| 1617 | mButtonManager = new ButtonManager(this); |
| 1618 | } |
| 1619 | return mButtonManager; |
Erin Dahlgren | 18e2ef6 | 2013-12-05 14:53:38 -0800 | [diff] [blame] | 1620 | } |
| 1621 | |
Sascha Haeberling | 88ef766 | 2013-08-15 17:19:22 -0700 | [diff] [blame] | 1622 | /** |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1623 | * Creates an AlertDialog appropriate for choosing whether to enable |
| 1624 | * location on the first run of the app. |
Erin Dahlgren | 491c628 | 2013-11-25 13:22:07 -0800 | [diff] [blame] | 1625 | */ |
| 1626 | public AlertDialog getFirstTimeLocationAlert() { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1627 | AlertDialog.Builder builder = new AlertDialog.Builder(mAppContext); |
Erin Dahlgren | 491c628 | 2013-11-25 13:22:07 -0800 | [diff] [blame] | 1628 | builder = SettingsView.getFirstTimeLocationAlertBuilder(builder, mSettingsController); |
| 1629 | if (builder != null) { |
| 1630 | return builder.create(); |
| 1631 | } else { |
| 1632 | return null; |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | /** |
Sascha Haeberling | e8959e7 | 2014-01-31 15:21:02 +0100 | [diff] [blame] | 1637 | * Launches an ACTION_EDIT intent for the given local data item. If |
| 1638 | * 'withTinyPlanet' is set, this will show a disambig dialog first to let |
| 1639 | * the user start either the tiny planet editor or another photo edior. |
| 1640 | * |
| 1641 | * @param data The data item to edit. |
Sascha Haeberling | 88ef766 | 2013-08-15 17:19:22 -0700 | [diff] [blame] | 1642 | */ |
| 1643 | public void launchEditor(LocalData data) { |
| 1644 | Intent intent = new Intent(Intent.ACTION_EDIT) |
| 1645 | .setDataAndType(data.getContentUri(), data.getMimeType()) |
| 1646 | .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
Erin Dahlgren | 05a0492 | 2013-11-07 11:35:10 -0800 | [diff] [blame] | 1647 | try { |
Angus Kong | 0eaf016 | 2013-12-16 15:53:30 -0800 | [diff] [blame] | 1648 | launchActivityByIntent(intent); |
Erin Dahlgren | 05a0492 | 2013-11-07 11:35:10 -0800 | [diff] [blame] | 1649 | } catch (ActivityNotFoundException e) { |
Angus Kong | 0eaf016 | 2013-12-16 15:53:30 -0800 | [diff] [blame] | 1650 | launchActivityByIntent(Intent.createChooser(intent, null)); |
Erin Dahlgren | 05a0492 | 2013-11-07 11:35:10 -0800 | [diff] [blame] | 1651 | } |
Sascha Haeberling | 88ef766 | 2013-08-15 17:19:22 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
Sascha Haeberling | e8959e7 | 2014-01-31 15:21:02 +0100 | [diff] [blame] | 1654 | @Override |
| 1655 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { |
| 1656 | super.onCreateContextMenu(menu, v, menuInfo); |
| 1657 | |
| 1658 | MenuInflater inflater = getMenuInflater(); |
| 1659 | inflater.inflate(R.menu.filmstrip_context_menu, menu); |
| 1660 | } |
| 1661 | |
| 1662 | @Override |
| 1663 | public boolean onContextItemSelected(MenuItem item) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1664 | switch (item.getItemId()) { |
Sascha Haeberling | e8959e7 | 2014-01-31 15:21:02 +0100 | [diff] [blame] | 1665 | case R.id.tiny_planet_editor: |
| 1666 | mMyFilmstripBottomControlListener.onTinyPlanet(); |
| 1667 | return true; |
| 1668 | case R.id.photo_editor: |
| 1669 | mMyFilmstripBottomControlListener.onEdit(); |
| 1670 | return true; |
| 1671 | } |
| 1672 | return false; |
| 1673 | } |
| 1674 | |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 1675 | /** |
| 1676 | * Launch the tiny planet editor. |
| 1677 | * |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1678 | * @param data The data must be a 360 degree stereographically mapped |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1679 | * panoramic image. It will not be modified, instead a new item |
| 1680 | * with the result will be added to the filmstrip. |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 1681 | */ |
| 1682 | public void launchTinyPlanetEditor(LocalData data) { |
| 1683 | TinyPlanetFragment fragment = new TinyPlanetFragment(); |
| 1684 | Bundle bundle = new Bundle(); |
| 1685 | bundle.putString(TinyPlanetFragment.ARGUMENT_URI, data.getContentUri().toString()); |
| 1686 | bundle.putString(TinyPlanetFragment.ARGUMENT_TITLE, data.getTitle()); |
| 1687 | fragment.setArguments(bundle); |
| 1688 | fragment.show(getFragmentManager(), "tiny_planet"); |
| 1689 | } |
| 1690 | |
Erin Dahlgren | 14466ba | 2014-02-03 14:01:54 -0800 | [diff] [blame] | 1691 | private void setBottomBarColor() { |
Erin Dahlgren | 4efa8b5 | 2013-12-17 18:31:35 -0800 | [diff] [blame] | 1692 | // Currently not all modules use the generic_module UI. |
Erin Dahlgren | cb99b3d | 2014-01-07 17:16:20 -0800 | [diff] [blame] | 1693 | // TODO: once all modules have a bottom bar, remove |
| 1694 | // isUsingBottomBar check. |
| 1695 | if (mCurrentModule.isUsingBottomBar()) { |
Erin Dahlgren | 14466ba | 2014-02-03 14:01:54 -0800 | [diff] [blame] | 1696 | int color = getResources().getColor(R.color.bottombar_unpressed); |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 1697 | mCameraAppUI.setBottomBarColor(color); |
Spike Sprague | b92910e | 2014-01-13 18:10:54 -0800 | [diff] [blame] | 1698 | |
Erin Dahlgren | 14466ba | 2014-02-03 14:01:54 -0800 | [diff] [blame] | 1699 | int pressedColor = getResources().getColor(R.color.bottombar_pressed); |
Spike Sprague | b92910e | 2014-01-13 18:10:54 -0800 | [diff] [blame] | 1700 | mCameraAppUI.setBottomBarPressedColor(pressedColor); |
Erin Dahlgren | 4efa8b5 | 2013-12-17 18:31:35 -0800 | [diff] [blame] | 1701 | } |
Erin Dahlgren | cb99b3d | 2014-01-07 17:16:20 -0800 | [diff] [blame] | 1702 | } |
Erin Dahlgren | 4efa8b5 | 2013-12-17 18:31:35 -0800 | [diff] [blame] | 1703 | |
Erin Dahlgren | 14466ba | 2014-02-03 14:01:54 -0800 | [diff] [blame] | 1704 | private void setBottomBarShutterIcon() { |
Erin Dahlgren | fecd723 | 2014-01-16 13:29:42 -0800 | [diff] [blame] | 1705 | // Currently not all modules use the generic_module UI. |
| 1706 | // TODO: once all modules have a bottom bar, remove |
| 1707 | // isUsingBottomBar check. |
| 1708 | if (mCurrentModule.isUsingBottomBar()) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1709 | int shutterIconId = CameraUtil.getCameraShutterIconId(mCurrentModeIndex, mAppContext); |
Erin Dahlgren | fecd723 | 2014-01-16 13:29:42 -0800 | [diff] [blame] | 1710 | mCameraAppUI.setBottomBarShutterIcon(shutterIconId); |
| 1711 | } |
| 1712 | } |
| 1713 | |
Erin Dahlgren | cb99b3d | 2014-01-07 17:16:20 -0800 | [diff] [blame] | 1714 | private void openModule(CameraModule module) { |
Erin Dahlgren | 14466ba | 2014-02-03 14:01:54 -0800 | [diff] [blame] | 1715 | // TODO: Remove setting color here when all modules use CameraAppUI. |
| 1716 | setBottomBarColor(); |
| 1717 | setBottomBarShutterIcon(); |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1718 | module.init(this, isSecureCamera(), isCaptureIntent()); |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1719 | module.resume(); |
Angus Kong | faaee01 | 2013-12-07 00:38:46 -0800 | [diff] [blame] | 1720 | module.onPreviewVisibilityChanged(!mFilmstripVisible); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | private void closeModule(CameraModule module) { |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1724 | module.pause(); |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1727 | private void performDeletion() { |
| 1728 | if (!mPendingDeletion) { |
| 1729 | return; |
| 1730 | } |
| 1731 | hideUndoDeletionBar(false); |
Sascha Haeberling | 44c1afb | 2013-12-20 11:59:35 -0800 | [diff] [blame] | 1732 | mDataAdapter.executeDeletion(); |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | public void showUndoDeletionBar() { |
| 1736 | if (mPendingDeletion) { |
| 1737 | performDeletion(); |
| 1738 | } |
| 1739 | Log.v(TAG, "showing undo bar"); |
| 1740 | mPendingDeletion = true; |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 1741 | if (mUndoDeletionBar == null) { |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1742 | ViewGroup v = (ViewGroup) getLayoutInflater().inflate(R.layout.undo_bar, |
| 1743 | mAboveFilmstripControlLayout, true); |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 1744 | mUndoDeletionBar = (ViewGroup) v.findViewById(R.id.camera_undo_deletion_bar); |
| 1745 | View button = mUndoDeletionBar.findViewById(R.id.camera_undo_deletion_button); |
| 1746 | button.setOnClickListener(new View.OnClickListener() { |
| 1747 | @Override |
| 1748 | public void onClick(View view) { |
| 1749 | mDataAdapter.undoDataRemoval(); |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1750 | hideUndoDeletionBar(true); |
| 1751 | } |
| 1752 | }); |
| 1753 | // Setting undo bar clickable to avoid touch events going through |
| 1754 | // the bar to the buttons (eg. edit button, etc) underneath the bar. |
| 1755 | mUndoDeletionBar.setClickable(true); |
| 1756 | // When there is user interaction going on with the undo button, we |
| 1757 | // do not want to hide the undo bar. |
| 1758 | button.setOnTouchListener(new View.OnTouchListener() { |
| 1759 | @Override |
| 1760 | public boolean onTouch(View v, MotionEvent event) { |
| 1761 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
| 1762 | mIsUndoingDeletion = true; |
| 1763 | } else if (event.getActionMasked() == MotionEvent.ACTION_UP) { |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1764 | mIsUndoingDeletion = false; |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1765 | } |
| 1766 | return false; |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 1767 | } |
| 1768 | }); |
| 1769 | } |
| 1770 | mUndoDeletionBar.setAlpha(0f); |
| 1771 | mUndoDeletionBar.setVisibility(View.VISIBLE); |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1772 | mUndoDeletionBar.animate().setDuration(200).alpha(1f).setListener(null).start(); |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1775 | private void hideUndoDeletionBar(boolean withAnimation) { |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 1776 | Log.v(TAG, "Hiding undo deletion bar"); |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1777 | mPendingDeletion = false; |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 1778 | if (mUndoDeletionBar != null) { |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1779 | if (withAnimation) { |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1780 | mUndoDeletionBar.animate().setDuration(200).alpha(0f) |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1781 | .setListener(new Animator.AnimatorListener() { |
| 1782 | @Override |
| 1783 | public void onAnimationStart(Animator animation) { |
| 1784 | // Do nothing. |
| 1785 | } |
| 1786 | |
| 1787 | @Override |
| 1788 | public void onAnimationEnd(Animator animation) { |
| 1789 | mUndoDeletionBar.setVisibility(View.GONE); |
| 1790 | } |
| 1791 | |
| 1792 | @Override |
| 1793 | public void onAnimationCancel(Animator animation) { |
| 1794 | // Do nothing. |
| 1795 | } |
| 1796 | |
| 1797 | @Override |
| 1798 | public void onAnimationRepeat(Animator animation) { |
| 1799 | // Do nothing. |
| 1800 | } |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1801 | }).start(); |
Doris Liu | 742cd5b | 2013-09-12 16:17:43 -0700 | [diff] [blame] | 1802 | } else { |
| 1803 | mUndoDeletionBar.setVisibility(View.GONE); |
| 1804 | } |
Angus Kong | 653c43b | 2013-08-21 18:28:43 -0700 | [diff] [blame] | 1805 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | @Override |
Angus Kong | 9f1db52 | 2013-11-09 16:25:59 -0800 | [diff] [blame] | 1809 | public void onOrientationChanged(int orientation) { |
| 1810 | // We keep the last known orientation. So if the user first orient |
| 1811 | // the camera then point the camera to floor or sky, we still have |
| 1812 | // the correct orientation. |
| 1813 | if (orientation == OrientationManager.ORIENTATION_UNKNOWN) { |
| 1814 | return; |
| 1815 | } |
| 1816 | mLastRawOrientation = orientation; |
| 1817 | if (mCurrentModule != null) { |
| 1818 | mCurrentModule.onOrientationChanged(orientation); |
| 1819 | } |
| 1820 | } |
| 1821 | |
Angus Kong | a719460 | 2013-09-06 17:20:15 -0700 | [diff] [blame] | 1822 | /** |
Sascha Haeberling | a5a08d7 | 2013-09-11 20:30:52 -0700 | [diff] [blame] | 1823 | * Enable/disable swipe-to-filmstrip. Will always disable swipe if in |
| 1824 | * capture intent. |
Angus Kong | a719460 | 2013-09-06 17:20:15 -0700 | [diff] [blame] | 1825 | * |
| 1826 | * @param enable {@code true} to enable swipe. |
| 1827 | */ |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1828 | public void setSwipingEnabled(boolean enable) { |
Angus Kong | 166e36f | 2013-12-03 08:54:42 -0800 | [diff] [blame] | 1829 | // TODO: Bring back the functionality. |
Angus Kong | a719460 | 2013-09-06 17:20:15 -0700 | [diff] [blame] | 1830 | if (isCaptureIntent()) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1831 | // lockPreview(true); |
Angus Kong | a719460 | 2013-09-06 17:20:15 -0700 | [diff] [blame] | 1832 | } else { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame^] | 1833 | // lockPreview(!enable); |
Angus Kong | a719460 | 2013-09-06 17:20:15 -0700 | [diff] [blame] | 1834 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | // Accessor methods for getting latency times used in performance testing |
Kevin Gabayan | a0e8347 | 2014-01-15 15:21:13 -0800 | [diff] [blame] | 1838 | public long getFirstPreviewTime() { |
| 1839 | if (mCurrentModule instanceof PhotoModule) { |
| 1840 | long coverHiddenTime = getCameraAppUI().getCoverHiddenTime(); |
| 1841 | if (coverHiddenTime != -1) { |
| 1842 | return coverHiddenTime - mOnCreateTime; |
| 1843 | } |
| 1844 | } |
| 1845 | return -1; |
| 1846 | } |
| 1847 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1848 | public long getAutoFocusTime() { |
| 1849 | return (mCurrentModule instanceof PhotoModule) ? |
| 1850 | ((PhotoModule) mCurrentModule).mAutoFocusTime : -1; |
| 1851 | } |
| 1852 | |
| 1853 | public long getShutterLag() { |
| 1854 | return (mCurrentModule instanceof PhotoModule) ? |
| 1855 | ((PhotoModule) mCurrentModule).mShutterLag : -1; |
| 1856 | } |
| 1857 | |
| 1858 | public long getShutterToPictureDisplayedTime() { |
| 1859 | return (mCurrentModule instanceof PhotoModule) ? |
| 1860 | ((PhotoModule) mCurrentModule).mShutterToPictureDisplayedTime : -1; |
| 1861 | } |
| 1862 | |
| 1863 | public long getPictureDisplayedToJpegCallbackTime() { |
| 1864 | return (mCurrentModule instanceof PhotoModule) ? |
| 1865 | ((PhotoModule) mCurrentModule).mPictureDisplayedToJpegCallbackTime : -1; |
| 1866 | } |
| 1867 | |
| 1868 | public long getJpegCallbackFinishTime() { |
| 1869 | return (mCurrentModule instanceof PhotoModule) ? |
| 1870 | ((PhotoModule) mCurrentModule).mJpegCallbackFinishTime : -1; |
| 1871 | } |
| 1872 | |
| 1873 | public long getCaptureStartTime() { |
| 1874 | return (mCurrentModule instanceof PhotoModule) ? |
| 1875 | ((PhotoModule) mCurrentModule).mCaptureStartTime : -1; |
| 1876 | } |
| 1877 | |
| 1878 | public boolean isRecording() { |
| 1879 | return (mCurrentModule instanceof VideoModule) ? |
| 1880 | ((VideoModule) mCurrentModule).isRecording() : false; |
| 1881 | } |
Angus Kong | 4f795b8 | 2013-09-16 14:25:35 -0700 | [diff] [blame] | 1882 | |
Angus Kong | 6284815 | 2013-11-08 17:25:29 -0800 | [diff] [blame] | 1883 | public CameraManager.CameraOpenCallback getCameraOpenErrorCallback() { |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1884 | return mCameraController; |
Angus Kong | 4f795b8 | 2013-09-16 14:25:35 -0700 | [diff] [blame] | 1885 | } |
Ruben Brunk | d217ed0 | 2013-10-08 23:31:13 -0700 | [diff] [blame] | 1886 | |
| 1887 | // For debugging purposes only. |
| 1888 | public CameraModule getCurrentModule() { |
| 1889 | return mCurrentModule; |
| 1890 | } |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1891 | |
| 1892 | private void keepScreenOnForAWhile() { |
| 1893 | if (mKeepScreenOn) { |
| 1894 | return; |
| 1895 | } |
| 1896 | mMainHandler.removeMessages(MSG_CLEAR_SCREEN_ON_FLAG); |
| 1897 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 1898 | mMainHandler.sendEmptyMessageDelayed(MSG_CLEAR_SCREEN_ON_FLAG, SCREEN_DELAY_MS); |
| 1899 | } |
| 1900 | |
| 1901 | private void resetScreenOn() { |
| 1902 | mKeepScreenOn = false; |
| 1903 | mMainHandler.removeMessages(MSG_CLEAR_SCREEN_ON_FLAG); |
| 1904 | getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 1905 | } |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1906 | |
Angus Kong | 6c0c7f1 | 2014-01-15 14:40:27 -0800 | [diff] [blame] | 1907 | /** |
| 1908 | * @return {@code true} if the Gallery is launched successfully. |
| 1909 | */ |
| 1910 | private boolean startGallery() { |
| 1911 | if (mGalleryIntent == null) { |
| 1912 | return false; |
| 1913 | } |
Angus Kong | d3de171 | 2013-12-12 22:01:12 -0800 | [diff] [blame] | 1914 | try { |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 1915 | UsageStatistics.changeScreen(NavigationChange.Mode.GALLERY, InteractionCause.BUTTON); |
Alan Newberger | 80461c2 | 2014-02-03 15:03:26 -0800 | [diff] [blame] | 1916 | Intent startGalleryIntent = new Intent(mGalleryIntent); |
| 1917 | int currentDataId = mFilmstripController.getCurrentId(); |
| 1918 | LocalData currentLocalData = mDataAdapter.getLocalData(currentDataId); |
| 1919 | if (currentLocalData != null) { |
| 1920 | GalleryHelper.setContentUri(startGalleryIntent, currentLocalData.getContentUri()); |
| 1921 | } |
| 1922 | launchActivityByIntent(startGalleryIntent); |
Angus Kong | d3de171 | 2013-12-12 22:01:12 -0800 | [diff] [blame] | 1923 | } catch (ActivityNotFoundException e) { |
| 1924 | Log.w(TAG, "Failed to launch gallery activity, closing"); |
| 1925 | } |
Angus Kong | 6c0c7f1 | 2014-01-15 14:40:27 -0800 | [diff] [blame] | 1926 | return false; |
Angus Kong | d3de171 | 2013-12-12 22:01:12 -0800 | [diff] [blame] | 1927 | } |
| 1928 | |
Angus Kong | 662fbf4 | 2013-12-12 13:22:03 -0800 | [diff] [blame] | 1929 | private void setNfcBeamPushUriFromData(LocalData data) { |
| 1930 | final Uri uri = data.getContentUri(); |
| 1931 | if (uri != Uri.EMPTY) { |
| 1932 | mNfcPushUris[0] = uri; |
| 1933 | } else { |
| 1934 | mNfcPushUris[0] = null; |
| 1935 | } |
| 1936 | } |
| 1937 | |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1938 | /** |
| 1939 | * Updates the visibility of the filmstrip bottom controls. |
| 1940 | */ |
| 1941 | private void updateUiByData(final int dataId) { |
| 1942 | if (isSecureCamera()) { |
| 1943 | // We cannot show buttons in secure camera since go to other |
| 1944 | // activities might create a security hole. |
| 1945 | return; |
| 1946 | } |
| 1947 | |
| 1948 | final LocalData currentData = mDataAdapter.getLocalData(dataId); |
| 1949 | if (currentData == null) { |
| 1950 | Log.w(TAG, "Current data ID not found."); |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1951 | hideSessionProgress(); |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1952 | return; |
| 1953 | } |
| 1954 | |
Angus Kong | 662fbf4 | 2013-12-12 13:22:03 -0800 | [diff] [blame] | 1955 | setNfcBeamPushUriFromData(currentData); |
| 1956 | |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1957 | /* Bottom controls. */ |
| 1958 | |
Angus Kong | e2f4c03 | 2013-12-19 10:24:33 -0800 | [diff] [blame] | 1959 | updateBottomControlsByData(currentData); |
| 1960 | if (!mDataAdapter.isMetadataUpdated(dataId)) { |
Sascha Haeberling | 44c1afb | 2013-12-20 11:59:35 -0800 | [diff] [blame] | 1961 | mDataAdapter.updateMetadata(dataId); |
Angus Kong | e2f4c03 | 2013-12-19 10:24:33 -0800 | [diff] [blame] | 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | /** |
| 1966 | * Updates the bottom controls based on the data. |
| 1967 | */ |
| 1968 | private void updateBottomControlsByData(final LocalData currentData) { |
| 1969 | |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1970 | final CameraAppUI.BottomControls filmstripBottomControls = |
| 1971 | mCameraAppUI.getFilmstripBottomControls(); |
Angus Kong | 740cbee | 2013-12-11 15:46:16 -0800 | [diff] [blame] | 1972 | filmstripBottomControls.setEditButtonVisibility( |
| 1973 | currentData.isDataActionSupported(LocalData.DATA_ACTION_EDIT)); |
Angus Kong | e0aff89 | 2013-12-11 20:51:01 -0800 | [diff] [blame] | 1974 | filmstripBottomControls.setShareButtonVisibility( |
| 1975 | currentData.isDataActionSupported(LocalData.DATA_ACTION_SHARE)); |
| 1976 | filmstripBottomControls.setDeleteButtonVisibility( |
| 1977 | currentData.isDataActionSupported(LocalData.DATA_ACTION_DELETE)); |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1978 | |
| 1979 | /* Progress bar */ |
| 1980 | |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1981 | Uri contentUri = currentData.getContentUri(); |
| 1982 | CaptureSessionManager sessionManager = getServices() |
| 1983 | .getCaptureSessionManager(); |
| 1984 | int sessionProgress = sessionManager.getSessionProgress(contentUri); |
| 1985 | |
| 1986 | if (sessionProgress < 0) { |
| 1987 | hideSessionProgress(); |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1988 | } else { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1989 | CharSequence progressMessage = sessionManager |
| 1990 | .getSessionProgressMessage(contentUri); |
| 1991 | showSessionProgress(progressMessage); |
| 1992 | updateSessionProgress(sessionProgress); |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | /* View button */ |
| 1996 | |
| 1997 | // We need to add this to a separate DB. |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 1998 | final int viewButtonVisibility; |
| 1999 | if (PanoramaMetadataLoader.isPanorama(currentData)) { |
Angus Kong | 00b3371 | 2014-01-16 11:06:46 -0800 | [diff] [blame] | 2000 | viewButtonVisibility = CameraAppUI.BottomControls.VIEWER_PHOTO_SPHERE; |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 2001 | } else if (RgbzMetadataLoader.hasRGBZData(currentData)) { |
Angus Kong | 00b3371 | 2014-01-16 11:06:46 -0800 | [diff] [blame] | 2002 | viewButtonVisibility = CameraAppUI.BottomControls.VIEWER_REFOCUS; |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 2003 | } else { |
Angus Kong | 00b3371 | 2014-01-16 11:06:46 -0800 | [diff] [blame] | 2004 | viewButtonVisibility = CameraAppUI.BottomControls.VIEWER_NONE; |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 2005 | } |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 2006 | |
Sascha Haeberling | e8959e7 | 2014-01-31 15:21:02 +0100 | [diff] [blame] | 2007 | filmstripBottomControls.setTinyPlanetEnabled( |
Angus Kong | 8a2350a | 2013-12-16 15:02:34 -0800 | [diff] [blame] | 2008 | PanoramaMetadataLoader.isPanorama360(currentData)); |
Angus Kong | 00b3371 | 2014-01-16 11:06:46 -0800 | [diff] [blame] | 2009 | filmstripBottomControls.setViewerButtonVisibility(viewButtonVisibility); |
Angus Kong | b251025 | 2013-12-10 22:58:15 -0800 | [diff] [blame] | 2010 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2011 | } |