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