diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/CameraActivity.java | 75 | ||||
-rw-r--r-- | src/com/android/camera/VideoUI.java | 2 | ||||
-rw-r--r-- | src/com/android/camera/data/LocalMediaData.java | 12 | ||||
-rw-r--r-- | src/com/android/camera/ui/CameraControls.java | 2 | ||||
-rw-r--r-- | src/com/android/camera/ui/FilmStripView.java | 54 |
5 files changed, 103 insertions, 42 deletions
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java index 3a3dd0cc1..aadb7d75c 100644 --- a/src/com/android/camera/CameraActivity.java +++ b/src/com/android/camera/CameraActivity.java @@ -25,6 +25,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; +import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.graphics.drawable.ColorDrawable; @@ -33,6 +34,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; +import android.preference.PreferenceManager; import android.provider.MediaStore; import android.provider.Settings; import android.util.Log; @@ -82,6 +84,8 @@ public class CameraActivity extends Activity "com.android.camera.action.TRIM"; public static final String MEDIA_ITEM_PATH = "media-item-path"; + private static final String PREF_STARTUP_MODULE_INDEX = "camera.startup_module"; + // The intent extra for camera from secure lock screen. True if the gallery // should only show newly captured pictures. sSecureAlbumId does not // increment. This is used when switching between camera, camcorder, and @@ -505,6 +509,10 @@ public class CameraActivity extends Activity // Handle presses on the action bar items switch (item.getItemId()) { + case android.R.id.home: + // ActionBar's Up/Home button was clicked + mFilmStripView.getController().goToFirstItem(); + return true; case R.id.action_delete: removeData(currentDataId); return true; @@ -637,13 +645,28 @@ public class CameraActivity extends Activity mFilmStripView.setPanoramaViewHelper(mPanoramaViewHelper); // Set up the camera preview first so the preview shows up ASAP. mFilmStripView.setListener(mFilmStripListener); + + int moduleIndex = -1; if (MediaStore.INTENT_ACTION_VIDEO_CAMERA.equals(getIntent().getAction()) || MediaStore.ACTION_VIDEO_CAPTURE.equals(getIntent().getAction())) { - mCurrentModule = new VideoModule(); - mCurrentModuleIndex = CameraSwitcher.VIDEO_MODULE_INDEX; + moduleIndex = CameraSwitcher.VIDEO_MODULE_INDEX; + } else if (MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA.equals(getIntent().getAction()) + || MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(getIntent() + .getAction()) + || MediaStore.ACTION_IMAGE_CAPTURE.equals(getIntent().getAction()) + || MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(getIntent().getAction())) { + moduleIndex = CameraSwitcher.PHOTO_MODULE_INDEX; } else { - mCurrentModule = new PhotoModule(); + // If the activity has not been started using an explicit intent, + // read the module index from the last time the user changed modes + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + moduleIndex = prefs.getInt(PREF_STARTUP_MODULE_INDEX, -1); + if (moduleIndex < 0) { + moduleIndex = CameraSwitcher.PHOTO_MODULE_INDEX; + } } + setModuleFromIndex(moduleIndex); + mCurrentModule.init(this, mCameraModuleRootView); mOrientationListener = new MyOrientationEventListener(this); mMainHandler = new Handler(getMainLooper()); @@ -760,6 +783,15 @@ public class CameraActivity extends Activity return super.onKeyUp(keyCode, event); } + @Override + public void onBackPressed() { + if (!mFilmStripView.inCameraFullscreen()) { + mFilmStripView.getController().goToFirstItem(); + } else if (!mCurrentModule.onBackPressed()) { + super.onBackPressed(); + } + } + public boolean isAutoRotateScreen() { return mAutoRotateScreen; } @@ -834,13 +866,32 @@ public class CameraActivity extends Activity } @Override - public void onCameraSelected(int i) { - if (mCurrentModuleIndex == i) return; + public void onCameraSelected(int moduleIndex) { + if (mCurrentModuleIndex == moduleIndex) return; CameraHolder.instance().keep(); closeModule(mCurrentModule); - mCurrentModuleIndex = i; - switch (i) { + setModuleFromIndex(moduleIndex); + + openModule(mCurrentModule); + mCurrentModule.onOrientationChanged(mLastRawOrientation); + if (mMediaSaveService != null) { + mCurrentModule.onMediaSaveServiceConnected(mMediaSaveService); + } + + // Store the module index so we can use it the next time the Camera + // starts up. + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + prefs.edit().putInt(PREF_STARTUP_MODULE_INDEX, moduleIndex).apply(); + } + + /** + * Sets the mCurrentModuleIndex, creates a new module instance for the + * given index an sets it as mCurrentModule. + */ + private void setModuleFromIndex(int moduleIndex) { + mCurrentModuleIndex = moduleIndex; + switch (moduleIndex) { case CameraSwitcher.VIDEO_MODULE_INDEX: mCurrentModule = new VideoModule(); break; @@ -850,14 +901,8 @@ public class CameraActivity extends Activity case CameraSwitcher.LIGHTCYCLE_MODULE_INDEX: mCurrentModule = PhotoSphereHelper.createPanoramaModule(); break; - default: - break; - } - - openModule(mCurrentModule); - mCurrentModule.onOrientationChanged(mLastRawOrientation); - if (mMediaSaveService != null) { - mCurrentModule.onMediaSaveServiceConnected(mMediaSaveService); + default: + break; } } diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java index 74d4cea9b..ad42b1aa0 100644 --- a/src/com/android/camera/VideoUI.java +++ b/src/com/android/camera/VideoUI.java @@ -168,7 +168,7 @@ public class VideoUI implements PieRenderer.PieListener, mActivity.getLayoutInflater().inflate(R.layout.video_module, (ViewGroup) mRootView, true); mTextureView = (TextureView) mRootView.findViewById(R.id.preview_content); mTextureView.setSurfaceTextureListener(this); - mRootView.addOnLayoutChangeListener(mLayoutListener); + mTextureView.addOnLayoutChangeListener(mLayoutListener); ((CameraRootView) mRootView).setDisplayChangeListener(this); mFlashOverlay = mRootView.findViewById(R.id.flash_overlay); mShutterButton = (ShutterButton) mRootView.findViewById(R.id.shutter_button); diff --git a/src/com/android/camera/data/LocalMediaData.java b/src/com/android/camera/data/LocalMediaData.java index fef141f55..53c153c0c 100644 --- a/src/com/android/camera/data/LocalMediaData.java +++ b/src/com/android/camera/data/LocalMediaData.java @@ -344,22 +344,28 @@ public abstract class LocalMediaData implements LocalData { int width = c.getInt(COL_WIDTH); int height = c.getInt(COL_HEIGHT); if (width <= 0 || height <= 0) { - Log.w(TAG, "Warning! zero dimension for " + Log.w(TAG, "Zero dimension in ContentResolver for " + path + ":" + width + "x" + height); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, opts); - if (opts.outWidth != -1 && opts.outHeight != -1) { + if (opts.outWidth > 0 && opts.outHeight > 0) { width = opts.outWidth; height = opts.outHeight; } else { - Log.w(TAG, "Warning! dimension decode failed for " + path); + Log.w(TAG, "Dimension decode failed for " + path); Bitmap b = BitmapFactory.decodeFile(path); if (b == null) { + Log.w(TAG, "PhotoData skipeped." + + " Decoding " + path + "failed."); return null; } width = b.getWidth(); height = b.getHeight(); + if (width == 0 || height == 0) { + Log.w(TAG, "PhotoData skipped. Bitmap size 0 for " + path); + return null; + } } } if (orientation == 90 || orientation == 270) { diff --git a/src/com/android/camera/ui/CameraControls.java b/src/com/android/camera/ui/CameraControls.java index ed281398b..d211f4eef 100644 --- a/src/com/android/camera/ui/CameraControls.java +++ b/src/com/android/camera/ui/CameraControls.java @@ -37,10 +37,12 @@ public class CameraControls extends RotatableLayout { public CameraControls(Context context, AttributeSet attrs) { super(context, attrs); + setMeasureAllChildren(true); } public CameraControls(Context context) { super(context); + setMeasureAllChildren(true); } @Override diff --git a/src/com/android/camera/ui/FilmStripView.java b/src/com/android/camera/ui/FilmStripView.java index dfb219a58..de57296bc 100644 --- a/src/com/android/camera/ui/FilmStripView.java +++ b/src/com/android/camera/ui/FilmStripView.java @@ -40,6 +40,8 @@ import com.android.camera.ui.FilmstripBottomControls.BottomControlsListener; import com.android.camera.util.PhotoSphereHelper.PanoramaViewHelper; import com.android.camera2.R; +import java.util.Arrays; + public class FilmStripView extends ViewGroup implements BottomControlsListener { private static final String TAG = "CAM_FilmStripView"; @@ -364,7 +366,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { public boolean isScrolling(); - public void goToCameraFullScreen(); + public void goToFirstItem(); public void goToFilmStrip(); @@ -1525,7 +1527,6 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { ViewItem curr = mViewItem[mCurrentItem]; int dataID = curr.getID(); if (reporter.isDataRemoved(dataID)) { - mCenterX = -1; reload(); return; } @@ -1570,10 +1571,23 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { /** * The whole data might be totally different. Flush all and load from the - * start. + * start. Filmstrip will be centered on the first item, i.e. the camera + * preview. */ private void reload() { - removeAllViews(); + // Remove all views from the mViewItem buffer, except the camera view. + for (int i = 0; i < mViewItem.length; i++) { + if (mViewItem[i] == null) { + continue; + } + View v = mViewItem[i].getView(); + if (v != mCameraView) { + removeView(v); + } + } + + // Clear out the mViewItems and rebuild with camera in the center. + Arrays.fill(mViewItem, null); int dataNumber = mDataAdapter.getTotalNumber(); if (dataNumber == 0) { return; @@ -1584,16 +1598,17 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { if (mViewItem[mCurrentItem] == null) { return; } - for (int i = 1; mCurrentItem + i < BUFFER_SIZE || mCurrentItem - i >= 0; i++) { - int itemID = mCurrentItem + i; - if (itemID < BUFFER_SIZE && mViewItem[itemID - 1] != null) { - mViewItem[itemID] = buildItemFromData(mViewItem[itemID - 1].getID() + 1); - } - itemID = mCurrentItem - i; - if (itemID >= 0 && mViewItem[itemID + 1] != null) { - mViewItem[itemID] = buildItemFromData(mViewItem[itemID + 1].getID() - 1); + for (int i = mCurrentItem + 1; i < BUFFER_SIZE; i++) { + mViewItem[i] = buildItemFromData(mViewItem[i - 1].getID() + 1); + if (mViewItem[i] == null) { + break; } } + + // Ensure that the views in mViewItem will layout the first in the + // center of the display upon a reload. + mCenterX = -1; + layoutChildren(); } @@ -1898,17 +1913,10 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { } @Override - public void goToCameraFullScreen() { - if (mDataAdapter.getImageData(0).getViewType() - != ImageData.TYPE_STICKY_VIEW) { - return; - } - goToFullScreen(); - scrollToPosition( - estimateMinX(mViewItem[mCurrentItem].getID(), - mViewItem[mCurrentItem].getLeftPosition(), - getWidth()), - GEOMETRY_ADJUST_TIME_MS, false); + public void goToFirstItem() { + // TODO: animate to camera if it is still in the mViewItem buffer + // versus a full reload which will perform an immediate transition + reload(); } @Override |