From 0fa0d96e5e0a8be32066740288ada89e938c33a8 Mon Sep 17 00:00:00 2001 From: Bobby Georgescu Date: Thu, 27 Sep 2012 16:36:03 -0700 Subject: Show a placeholder when the camera filmstrip is empty Bug: 7213757 Tapping the placeholder takes the user back to the full-screen camera capture mode. Change-Id: I844f789b8e80f34e79f4a9c366c1c244bbf1f2a5 --- src/com/android/gallery3d/app/PhotoPage.java | 19 +++- src/com/android/gallery3d/data/ActionImage.java | 103 +++++++++++++++++++++ .../android/gallery3d/data/EmptyAlbumImage.java | 34 +++++++ .../gallery3d/data/FilterEmptyPromptSet.java | 82 ++++++++++++++++ src/com/android/gallery3d/data/FilterSource.java | 18 ++++ src/com/android/gallery3d/data/MediaObject.java | 2 + src/com/android/gallery3d/data/UnlockImage.java | 76 +-------------- src/com/android/gallery3d/ui/PhotoView.java | 2 +- 8 files changed, 261 insertions(+), 75 deletions(-) create mode 100644 src/com/android/gallery3d/data/ActionImage.java create mode 100644 src/com/android/gallery3d/data/EmptyAlbumImage.java create mode 100644 src/com/android/gallery3d/data/FilterEmptyPromptSet.java (limited to 'src/com') diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index caa5fde61..ec1f8142e 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -19,7 +19,6 @@ package com.android.gallery3d.app; import android.annotation.TargetApi; import android.app.Activity; import android.content.ActivityNotFoundException; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -75,7 +74,6 @@ import com.android.gallery3d.ui.SelectionManager; import com.android.gallery3d.ui.SynchronizedHandler; import com.android.gallery3d.util.GalleryUtils; import com.android.gallery3d.util.LightCycleHelper; -import com.android.gallery3d.util.MediaSetUtils; public class PhotoPage extends ActivityState implements PhotoView.Listener, OrientationManager.Listener, AppBridge.Server, @@ -335,6 +333,11 @@ public class PhotoPage extends ActivityState implements mFlags |= FLAG_SHOW_WHEN_LOCKED; } + // Don't display "empty album" action item for capture intents + if(!mSetPathString.equals("/local/all/0")) { + mSetPathString = "/filter/empty/{"+mSetPathString+"}"; + } + // Combine the original MediaSet with the one for ScreenNail // from AppBridge. mSetPathString = "/combo/item/{" + screenNailSetPath + @@ -533,6 +536,15 @@ public class PhotoPage extends ActivityState implements if (mCurrentPhoto == photo) return; mCurrentPhoto = photo; if (mCurrentPhoto == null) return; + + // If by swiping or deletion the user ends up on an action item + // and zoomed in, zoom out so that the context of the action is + // more clear + if ((photo.getSupportedOperations() & MediaObject.SUPPORT_ACTION) != 0 + && !mPhotoView.getFilmMode()) { + mPhotoView.setFilmMode(true); + } + updateMenuOperations(); updateTitle(); if (mBottomControls != null) mBottomControls.refresh(); @@ -926,6 +938,7 @@ public class PhotoPage extends ActivityState implements boolean viewPanorama = (mSecureAlbum == null) && ((supported & MediaItem.SUPPORT_PANORAMA) != 0); boolean unlock = ((supported & MediaItem.SUPPORT_UNLOCK) != 0); + boolean goBack = ((supported & MediaItem.SUPPORT_BACK) != 0); if (playVideo) { // determine if the point is at center (1/6) of the photo view. @@ -940,6 +953,8 @@ public class PhotoPage extends ActivityState implements playVideo(mActivity, item.getPlayUri(), item.getName()); } else if (viewPanorama) { LightCycleHelper.viewPanorama(mActivity, item.getContentUri()); + } else if (goBack) { + onBackPressed(); } else if (unlock) { mActivity.getStateManager().finishState(this); } else { diff --git a/src/com/android/gallery3d/data/ActionImage.java b/src/com/android/gallery3d/data/ActionImage.java new file mode 100644 index 000000000..58e30b146 --- /dev/null +++ b/src/com/android/gallery3d/data/ActionImage.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.gallery3d.data; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.BitmapRegionDecoder; +import android.net.Uri; + +import com.android.gallery3d.app.GalleryApp; +import com.android.gallery3d.common.BitmapUtils; +import com.android.gallery3d.common.Utils; +import com.android.gallery3d.util.ThreadPool.Job; +import com.android.gallery3d.util.ThreadPool.JobContext; + +public class ActionImage extends MediaItem { + @SuppressWarnings("unused") + private static final String TAG = "ActionImage"; + private GalleryApp mApplication; + private int mResourceId; + + public ActionImage(Path path, GalleryApp application, int resourceId) { + super(path, nextVersionNumber()); + mApplication = Utils.checkNotNull(application); + mResourceId = resourceId; + } + + @Override + public Job requestImage(int type) { + return new BitmapJob(type); + } + + @Override + public Job requestLargeImage() { + return null; + } + + private class BitmapJob implements Job { + private int mType; + + protected BitmapJob(int type) { + mType = type; + } + + @Override + public Bitmap run(JobContext jc) { + int targetSize = MediaItem.getTargetSize(mType); + Bitmap bitmap = BitmapFactory.decodeResource(mApplication.getResources(), + mResourceId); + + if (mType == MediaItem.TYPE_MICROTHUMBNAIL) { + bitmap = BitmapUtils.resizeAndCropCenter(bitmap, targetSize, true); + } else { + bitmap = BitmapUtils.resizeDownBySideLength(bitmap, targetSize, true); + } + return bitmap; + } + } + + @Override + public int getSupportedOperations() { + return SUPPORT_ACTION; + } + + @Override + public int getMediaType() { + return MEDIA_TYPE_UNKNOWN; + } + + @Override + public Uri getContentUri() { + return null; + } + + @Override + public String getMimeType() { + return ""; + } + + @Override + public int getWidth() { + return 0; + } + + @Override + public int getHeight() { + return 0; + } +} diff --git a/src/com/android/gallery3d/data/EmptyAlbumImage.java b/src/com/android/gallery3d/data/EmptyAlbumImage.java new file mode 100644 index 000000000..dbbc01a33 --- /dev/null +++ b/src/com/android/gallery3d/data/EmptyAlbumImage.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.gallery3d.data; + +import com.android.gallery3d.R; +import com.android.gallery3d.app.GalleryApp; + +public class EmptyAlbumImage extends ActionImage { + @SuppressWarnings("unused") + private static final String TAG = "EmptyAlbumImage"; + + public EmptyAlbumImage(Path path, GalleryApp application) { + super(path, application, R.drawable.ic_menu_revert_holo_dark); + } + + @Override + public int getSupportedOperations() { + return super.getSupportedOperations() | SUPPORT_BACK; + } +} diff --git a/src/com/android/gallery3d/data/FilterEmptyPromptSet.java b/src/com/android/gallery3d/data/FilterEmptyPromptSet.java new file mode 100644 index 000000000..b576e06d4 --- /dev/null +++ b/src/com/android/gallery3d/data/FilterEmptyPromptSet.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.gallery3d.data; + +import java.util.ArrayList; + +public class FilterEmptyPromptSet extends MediaSet implements ContentListener { + @SuppressWarnings("unused") + private static final String TAG = "FilterEmptyPromptSet"; + + private ArrayList mEmptyItem; + private MediaSet mBaseSet; + + public FilterEmptyPromptSet(Path path, MediaSet baseSet, MediaItem emptyItem) { + super(path, INVALID_DATA_VERSION); + mEmptyItem = new ArrayList(1); + mEmptyItem.add(emptyItem); + mBaseSet = baseSet; + mBaseSet.addContentListener(this); + } + + @Override + public int getMediaItemCount() { + int itemCount = mBaseSet.getMediaItemCount(); + if (itemCount > 0) { + return itemCount; + } else { + return 1; + } + } + + @Override + public ArrayList getMediaItem(int start, int count) { + int itemCount = mBaseSet.getMediaItemCount(); + if (itemCount > 0) { + return mBaseSet.getMediaItem(start, count); + } else if (start == 0 && count == 1) { + return mEmptyItem; + } else { + throw new ArrayIndexOutOfBoundsException(); + } + } + + @Override + public void onContentDirty() { + notifyContentChanged(); + } + + @Override + public boolean isLeafAlbum() { + return true; + } + + @Override + public boolean isCameraRoll() { + return mBaseSet.isCameraRoll(); + } + + @Override + public long reload() { + return mBaseSet.reload(); + } + + @Override + public String getName() { + return mBaseSet.getName(); + } +} diff --git a/src/com/android/gallery3d/data/FilterSource.java b/src/com/android/gallery3d/data/FilterSource.java index e3f350f76..3244da34f 100644 --- a/src/com/android/gallery3d/data/FilterSource.java +++ b/src/com/android/gallery3d/data/FilterSource.java @@ -23,9 +23,14 @@ class FilterSource extends MediaSource { private static final String TAG = "FilterSource"; private static final int FILTER_BY_MEDIATYPE = 0; private static final int FILTER_BY_DELETE = 1; + private static final int FILTER_BY_EMPTY = 2; + private static final int FILTER_BY_EMPTY_ITEM = 3; + + public static final String FILTER_EMPTY_ITEM = "/filter/empty_prompt"; private GalleryApp mApplication; private PathMatcher mMatcher; + private MediaItem mEmptyItem; public FilterSource(GalleryApp application) { super("filter"); @@ -33,6 +38,11 @@ class FilterSource extends MediaSource { mMatcher = new PathMatcher(); mMatcher.add("/filter/mediatype/*/*", FILTER_BY_MEDIATYPE); mMatcher.add("/filter/delete/*", FILTER_BY_DELETE); + mMatcher.add("/filter/empty/*", FILTER_BY_EMPTY); + mMatcher.add("/filter/empty_item", FILTER_BY_EMPTY_ITEM); + + mEmptyItem = new EmptyAlbumImage(Path.fromString(FILTER_EMPTY_ITEM), + mApplication); } // The name we accept are: @@ -54,6 +64,14 @@ class FilterSource extends MediaSource { MediaSet[] sets = dataManager.getMediaSetsFromString(setsName); return new FilterDeleteSet(path, sets[0]); } + case FILTER_BY_EMPTY: { + String setsName = mMatcher.getVar(0); + MediaSet[] sets = dataManager.getMediaSetsFromString(setsName); + return new FilterEmptyPromptSet(path, sets[0], mEmptyItem); + } + case FILTER_BY_EMPTY_ITEM: { + return mEmptyItem; + } default: throw new RuntimeException("bad path: " + path); } diff --git a/src/com/android/gallery3d/data/MediaObject.java b/src/com/android/gallery3d/data/MediaObject.java index b4aa8d861..9e8d84ca7 100644 --- a/src/com/android/gallery3d/data/MediaObject.java +++ b/src/com/android/gallery3d/data/MediaObject.java @@ -39,6 +39,8 @@ public abstract class MediaObject { public static final int SUPPORT_TRIM = 1 << 12; public static final int SUPPORT_PANORAMA = 1 << 13; public static final int SUPPORT_UNLOCK = 1 << 14; + public static final int SUPPORT_BACK = 1 << 15; + public static final int SUPPORT_ACTION = 1 << 16; public static final int SUPPORT_ALL = 0xffffffff; // These are the bits returned from getMediaType(): diff --git a/src/com/android/gallery3d/data/UnlockImage.java b/src/com/android/gallery3d/data/UnlockImage.java index d09856d69..19189e42d 100644 --- a/src/com/android/gallery3d/data/UnlockImage.java +++ b/src/com/android/gallery3d/data/UnlockImage.java @@ -16,87 +16,19 @@ package com.android.gallery3d.data; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.BitmapRegionDecoder; -import android.net.Uri; - -import com.android.gallery3d.app.GalleryApp; -import com.android.gallery3d.common.BitmapUtils; -import com.android.gallery3d.common.Utils; -import com.android.gallery3d.util.ThreadPool.Job; -import com.android.gallery3d.util.ThreadPool.JobContext; import com.android.gallery3d.R; +import com.android.gallery3d.app.GalleryApp; -public class UnlockImage extends MediaItem { +public class UnlockImage extends ActionImage { @SuppressWarnings("unused") private static final String TAG = "UnlockImage"; - private GalleryApp mApplication; public UnlockImage(Path path, GalleryApp application) { - super(path, nextVersionNumber()); - mApplication = Utils.checkNotNull(application); - } - - @Override - public Job requestImage(int type) { - return new BitmapJob(type); - } - - @Override - public Job requestLargeImage() { - return null; - } - - private class BitmapJob implements Job { - private int mType; - - protected BitmapJob(int type) { - mType = type; - } - - @Override - public Bitmap run(JobContext jc) { - int targetSize = MediaItem.getTargetSize(mType); - Bitmap bitmap = BitmapFactory.decodeResource(mApplication.getResources(), - R.drawable.ic_lockscreen_handle_normal); - - if (mType == MediaItem.TYPE_MICROTHUMBNAIL) { - bitmap = BitmapUtils.resizeAndCropCenter(bitmap, targetSize, true); - } else { - bitmap = BitmapUtils.resizeDownBySideLength(bitmap, targetSize, true); - } - return bitmap; - } + super(path, application, R.drawable.ic_lockscreen_handle_normal); } @Override public int getSupportedOperations() { - return SUPPORT_UNLOCK; - } - - @Override - public int getMediaType() { - return MEDIA_TYPE_IMAGE; - } - - @Override - public Uri getContentUri() { - return null; - } - - @Override - public String getMimeType() { - return ""; - } - - @Override - public int getWidth() { - return 0; - } - - @Override - public int getHeight() { - return 0; + return super.getSupportedOperations() | SUPPORT_UNLOCK; } } diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java index 2fbc3ff7e..df7ab4c58 100644 --- a/src/com/android/gallery3d/ui/PhotoView.java +++ b/src/com/android/gallery3d/ui/PhotoView.java @@ -971,7 +971,7 @@ public class PhotoView extends GLView { MediaItem item = mModel.getMediaItem(0); int supported = 0; if (item != null) supported = item.getSupportedOperations(); - if ((supported & MediaItem.SUPPORT_UNLOCK) == 0) { + if ((supported & MediaItem.SUPPORT_ACTION) == 0) { setFilmMode(false); mIgnoreUpEvent = true; return true; -- cgit v1.2.3