From 6efbd7283aea80eef8e5001291eb53c9e156e88c Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Thu, 15 Mar 2012 15:23:00 -0700 Subject: bug #6176711: guard against null GalleryActionBar. When entering Gallery app from WallPaper picker, the activity is DialogPicker, which doesn't initialize GalleryActionbar so getGalleryActionbar() returns null. Guard against using the null object. I fixed the obvious NPE here, but Ray or Yuli should take a closer look, to see why this is broken. Change-Id: Ic6923c388ea7b72ab402131fc3b039546509e340 --- src/com/android/gallery3d/app/ActivityState.java | 5 ++++- src/com/android/gallery3d/app/AlbumPage.java | 5 ++++- src/com/android/gallery3d/app/PhotoPage.java | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/com/android/gallery3d/app/ActivityState.java b/src/com/android/gallery3d/app/ActivityState.java index 443e2bd29..384ae734b 100644 --- a/src/com/android/gallery3d/app/ActivityState.java +++ b/src/com/android/gallery3d/app/ActivityState.java @@ -141,7 +141,10 @@ abstract public class ActivityState { actionBar.show(); } int stateCount = mActivity.getStateManager().getStateCount(); - mActivity.getGalleryActionBar().setDisplayOptions(stateCount > 1, true); + GalleryActionBar galleryActionbar = mActivity.getGalleryActionBar(); + if (galleryActionbar != null) { + galleryActionbar.setDisplayOptions(stateCount > 1, true); + } // Default behavior, this can be overridden in ActivityState's onResume. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index 411464e86..32c5b7fc2 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -319,7 +319,10 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster Path path = mMediaSet.getPath(); boolean enableHomeButton = (mActivity.getStateManager().getStateCount() > 1) | mParentMediaSetString != null; - mActivity.getGalleryActionBar().setDisplayOptions(enableHomeButton, true); + GalleryActionBar galleryActionBar = mActivity.getGalleryActionBar(); + if (galleryActionBar != null) { + galleryActionBar.setDisplayOptions(enableHomeButton, true); + } // Set the reload bit here to prevent it exit this page in clearLoadingBit(). setLoadingBit(BIT_LOADING_RELOAD); diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 8040a2fc6..a8c69b567 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -630,8 +630,10 @@ public class PhotoPage extends ActivityState if (mMenuVisibilityListener == null) { mMenuVisibilityListener = new MyMenuVisibilityListener(); } - mActivity.getGalleryActionBar().setDisplayOptions(mSetPathString != null, true); - + GalleryActionBar galleryActionBar = mActivity.getGalleryActionBar(); + if (galleryActionBar != null) { + galleryActionBar.setDisplayOptions(mSetPathString != null, true); + } mActionBar.addOnMenuVisibilityListener(mMenuVisibilityListener); onUserInteraction(); } -- cgit v1.2.3 From 88d715de7a950616371b771dbb6a124b1718914b Mon Sep 17 00:00:00 2001 From: Yuli Huang Date: Thu, 12 Apr 2012 23:45:49 +0800 Subject: Fix SinglePhotoDataAdapter getScreenNail() bug:6322259 Change-Id: I6cf5de88fc07e4b73b028faa3b2a063b4d47fd20 --- src/com/android/gallery3d/app/SinglePhotoDataAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java b/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java index 6ef5040f3..315f5b59c 100644 --- a/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java +++ b/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java @@ -158,7 +158,7 @@ public class SinglePhotoDataAdapter extends TileImageViewAdapter } public ScreenNail getScreenNail(int offset) { - return null; + return (offset == 0) ? getScreenNail() : null; } public void next() { -- cgit v1.2.3 From a9f3be9c7e80e26c0c09ca45d829269c49d8835d Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Fri, 13 Apr 2012 12:33:29 +0800 Subject: Fix ANR in PhotoPage. This bugs happens because we open too many PhotoPage(s) (and onSingleTapUp is a delayed event). However, each of the PhotoPage need a Thread to run tile decoder. When we close one of the PhotoPage, it will wait the tile decoder to get finished first. However, the title decoder may still waiting in the queue and never got a chance to run. Change-Id: I113d1150729892edb4fe36bc5a1dc131db300476 fix: 6319833 --- src/com/android/gallery3d/app/AlbumPage.java | 1 + src/com/android/gallery3d/app/AlbumSetPage.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index efffe4075..0fcd7a759 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -164,6 +164,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } private void onSingleTapUp(int slotIndex) { + if (!mIsActive) return; MediaItem item = mAlbumDataAdapter.get(slotIndex); if (item == null) { Log.w(TAG, "item not ready yet, ignore the click"); diff --git a/src/com/android/gallery3d/app/AlbumSetPage.java b/src/com/android/gallery3d/app/AlbumSetPage.java index cbd6789b4..60de019de 100644 --- a/src/com/android/gallery3d/app/AlbumSetPage.java +++ b/src/com/android/gallery3d/app/AlbumSetPage.java @@ -172,6 +172,7 @@ public class AlbumSetPage extends ActivityState implements } public void onSingleTapUp(int slotIndex) { + if (!mIsActive) return; MediaSet targetSet = mAlbumSetDataAdapter.getMediaSet(slotIndex); if (targetSet == null) return; // Content is dirty, we shall reload soon -- cgit v1.2.3 From c6aae5f6356fa3bad1b82a71b51fddff8e21858b Mon Sep 17 00:00:00 2001 From: Wu-cheng Li Date: Mon, 30 Apr 2012 23:49:17 +0800 Subject: Fix crash when select all is pressed. bug:6411186 Change-Id: Iaa71a320bc4d6d70aade41d5144f75ba6db36e6d --- src/com/android/gallery3d/ui/MenuExecutor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/com/android/gallery3d/ui/MenuExecutor.java b/src/com/android/gallery3d/ui/MenuExecutor.java index a0f344982..a052c500d 100644 --- a/src/com/android/gallery3d/ui/MenuExecutor.java +++ b/src/com/android/gallery3d/ui/MenuExecutor.java @@ -185,12 +185,14 @@ public class MenuExecutor { } else { mSelectionManager.selectAll(); } + return; case R.id.action_crop: { Path path = getSingleSelectedPath(); String mimeType = getMimeType(manager.getMediaType(path)); Intent intent = new Intent(CropImage.ACTION_CROP) .setDataAndType(manager.getContentUri(path), mimeType); ((Activity) mActivity).startActivity(intent); + return; } case R.id.action_setas: { Path path = getSingleSelectedPath(); @@ -203,6 +205,7 @@ public class MenuExecutor { Activity activity = (Activity) mActivity; activity.startActivity(Intent.createChooser( intent, activity.getString(R.string.set_as))); + return; } case R.id.action_delete: title = R.string.delete; @@ -368,4 +371,3 @@ public class MenuExecutor { } } } - -- cgit v1.2.3 From ca4dafb77b8c427838803983e360d7c9fe70b32b Mon Sep 17 00:00:00 2001 From: Chih-Chung Chang Date: Tue, 1 May 2012 02:25:09 +0800 Subject: Fix black screen when viewing Gmail image file attachment. Bug: 6415848 Change-Id: Iec369866be6b5546fbd8cb77eb95a29f92e00b84 --- src/com/android/gallery3d/ui/PositionController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java index ac0d191f4..03fe65b1c 100644 --- a/src/com/android/gallery3d/ui/PositionController.java +++ b/src/com/android/gallery3d/ui/PositionController.java @@ -1012,7 +1012,8 @@ class PositionController { float hFactor = 1.0f; int viewW, viewH; - if (!mFilmMode && mConstrained && b == mBoxes.get(0)) { + if (!mFilmMode && mConstrained && !mConstrainedFrame.isEmpty() + && b == mBoxes.get(0)) { viewW = mConstrainedFrame.width(); viewH = mConstrainedFrame.height(); } else { -- cgit v1.2.3 From faac4c284d470bc5fa380a37a22272a65931cad7 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 16 May 2012 11:29:06 -0700 Subject: Restore deleted string still referenced from menu resource. Change-Id: I518dc004a92ee68682c2085c8d2f002896198feb --- res/values/strings.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/res/values/strings.xml b/res/values/strings.xml index bba7e33e6..4d23b0f10 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -59,6 +59,9 @@ Start over + + OK OK -- cgit v1.2.3 From 8130925c60b786759e852a6088776c626d8ee0e2 Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Wed, 16 May 2012 10:54:14 -0700 Subject: Fix a dead lock while we freeze the screen. bug: 6504696 Change-Id: If960967142bb0df773ce075bf76f5726c37e1d27 --- src/com/android/gallery3d/app/PhotoPage.java | 1 - src/com/android/gallery3d/ui/GLRoot.java | 1 + src/com/android/gallery3d/ui/GLRootView.java | 40 +++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index a46c777fa..2022a6e2d 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -56,7 +56,6 @@ import com.android.gallery3d.ui.GLView; import com.android.gallery3d.ui.ImportCompleteListener; import com.android.gallery3d.ui.MenuExecutor; import com.android.gallery3d.ui.PhotoView; -import com.android.gallery3d.ui.ScreenNail; import com.android.gallery3d.ui.SelectionManager; import com.android.gallery3d.ui.SynchronizedHandler; import com.android.gallery3d.util.GalleryUtils; diff --git a/src/com/android/gallery3d/ui/GLRoot.java b/src/com/android/gallery3d/ui/GLRoot.java index 5ed323a88..f4b7572a7 100644 --- a/src/com/android/gallery3d/ui/GLRoot.java +++ b/src/com/android/gallery3d/ui/GLRoot.java @@ -17,6 +17,7 @@ package com.android.gallery3d.ui; import android.graphics.Matrix; + import com.android.gallery3d.anim.CanvasAnimation; public interface GLRoot { diff --git a/src/com/android/gallery3d/ui/GLRootView.java b/src/com/android/gallery3d/ui/GLRootView.java index 1f25b9085..73e982509 100644 --- a/src/com/android/gallery3d/ui/GLRootView.java +++ b/src/com/android/gallery3d/ui/GLRootView.java @@ -19,12 +19,12 @@ package com.android.gallery3d.ui; import android.content.Context; import android.graphics.Matrix; import android.graphics.PixelFormat; -import android.graphics.Rect; import android.opengl.GLSurfaceView; import android.os.Process; import android.os.SystemClock; import android.util.AttributeSet; import android.view.MotionEvent; +import android.view.SurfaceHolder; import com.android.gallery3d.anim.CanvasAnimation; import com.android.gallery3d.common.Utils; @@ -467,6 +467,7 @@ public class GLRootView extends GLSurfaceView @Override public void onPause() { + unfreeze(); super.onPause(); if (DEBUG_PROFILE) { Log.d(TAG, "Stop profiling"); @@ -510,4 +511,41 @@ public class GLRootView extends GLSurfaceView mFreezeCondition.signalAll(); mRenderLock.unlock(); } + + // We need to unfreeze in the following methods and in onPause(). + // These methods will wait on GLThread. If we have freezed the GLRootView, + // the GLThread will wait on main thread to call unfreeze and cause dead + // lock. + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { + unfreeze(); + super.surfaceChanged(holder, format, w, h); + } + + @Override + public void surfaceCreated(SurfaceHolder holder) { + unfreeze(); + super.surfaceCreated(holder); + } + + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + unfreeze(); + super.surfaceDestroyed(holder); + } + + @Override + protected void onDetachedFromWindow() { + unfreeze(); + super.onDetachedFromWindow(); + } + + @Override + protected void finalize() throws Throwable { + try { + unfreeze(); + } finally { + super.finalize(); + } + } } -- cgit v1.2.3 From 92fc4eb8ea97843b42431eadcfa2277a8b236dc2 Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Thu, 17 May 2012 13:04:35 -0700 Subject: Fix a NPE found by Moneky. AlbumLabelMaker.mBitmapPool could be null if the setLabelWidth() has never been called or called with width as 0. bug:6510386 Change-Id: Idaaa0a1a7239271ba3ae3217e65029b382464c10 --- src/com/android/gallery3d/ui/AlbumLabelMaker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/gallery3d/ui/AlbumLabelMaker.java b/src/com/android/gallery3d/ui/AlbumLabelMaker.java index f837092b8..93b37ce13 100644 --- a/src/com/android/gallery3d/ui/AlbumLabelMaker.java +++ b/src/com/android/gallery3d/ui/AlbumLabelMaker.java @@ -211,6 +211,6 @@ public class AlbumLabelMaker { } public void clearRecycledLabels() { - mBitmapPool.clear(); + if (mBitmapPool != null) mBitmapPool.clear(); } } -- cgit v1.2.3 From 26be5cc3130f273dcb8c79a024a3df43d5ce9e60 Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Mon, 21 May 2012 16:52:25 -0700 Subject: Limit the size of a ScreenNail. bug:6528366 This bug was happened because we are trying to make a texture beyond the max size allowed in GL. Here is what we do in this CL: 1. Limit the size of a screen nail 2. Print warning message, if we try to allocate a texture beyond the size 3. Don't show fall-back animation if the image is not loaded yet. Change-Id: I004b1138efd0eef7ba11aa89556f67743ca46745 --- src/com/android/gallery3d/app/PhotoDataAdapter.java | 6 +++--- src/com/android/gallery3d/ui/BasicTexture.java | 6 ++++++ src/com/android/gallery3d/ui/BitmapScreenNail.java | 21 +++++++++++++++------ src/com/android/gallery3d/ui/GLRootView.java | 2 +- src/com/android/gallery3d/ui/PhotoView.java | 5 ++++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/com/android/gallery3d/app/PhotoDataAdapter.java b/src/com/android/gallery3d/app/PhotoDataAdapter.java index 6ba1ff69b..29154a082 100644 --- a/src/com/android/gallery3d/app/PhotoDataAdapter.java +++ b/src/com/android/gallery3d/app/PhotoDataAdapter.java @@ -415,7 +415,7 @@ public class PhotoDataAdapter implements PhotoPage.Model { // Create a default ScreenNail if the real one is not available yet. if (entry.screenNail == null) { - entry.screenNail = newDefaultScreenNail(item); + entry.screenNail = newPlaceholderScreenNail(item); if (offset == 0) updateTileProvider(entry); } @@ -632,7 +632,7 @@ public class PhotoDataAdapter implements PhotoPage.Model { // If this is a temporary item, don't try to get its bitmap because // it won't be available. We will get its bitmap after a data reload. if (isTemporaryItem(mItem)) { - return newDefaultScreenNail(mItem); + return newPlaceholderScreenNail(mItem); } Bitmap bitmap = mItem.requestImage(MediaItem.TYPE_THUMBNAIL).run(jc); @@ -687,7 +687,7 @@ public class PhotoDataAdapter implements PhotoPage.Model { // Create a default ScreenNail when a ScreenNail is needed, but we don't yet // have one available (because the image data is still being saved, or the // Bitmap is still being loaded. - private ScreenNail newDefaultScreenNail(MediaItem item) { + private ScreenNail newPlaceholderScreenNail(MediaItem item) { int width = item.getWidth(); int height = item.getHeight(); return new BitmapScreenNail(width, height); diff --git a/src/com/android/gallery3d/ui/BasicTexture.java b/src/com/android/gallery3d/ui/BasicTexture.java index 6a9a17d92..68a5b7d32 100644 --- a/src/com/android/gallery3d/ui/BasicTexture.java +++ b/src/com/android/gallery3d/ui/BasicTexture.java @@ -33,6 +33,8 @@ abstract class BasicTexture implements Texture { protected static final int STATE_LOADED = 1; protected static final int STATE_ERROR = -1; + private static final int MAX_TEXTURE_SIZE = 2048; + protected int mId; protected int mState; @@ -75,6 +77,10 @@ abstract class BasicTexture implements Texture { mHeight = height; mTextureWidth = Utils.nextPowerOf2(width); mTextureHeight = Utils.nextPowerOf2(height); + if (mTextureWidth > MAX_TEXTURE_SIZE || mTextureHeight > MAX_TEXTURE_SIZE) { + Log.w(TAG, String.format("texture is too large: %d x %d", + mTextureWidth, mTextureHeight), new Exception()); + } } public int getId() { diff --git a/src/com/android/gallery3d/ui/BitmapScreenNail.java b/src/com/android/gallery3d/ui/BitmapScreenNail.java index 14d3f1919..5c917570d 100644 --- a/src/com/android/gallery3d/ui/BitmapScreenNail.java +++ b/src/com/android/gallery3d/ui/BitmapScreenNail.java @@ -18,7 +18,6 @@ package com.android.gallery3d.ui; import android.graphics.Bitmap; import android.graphics.RectF; -import android.util.Log; import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.MediaItem; @@ -35,6 +34,9 @@ public class BitmapScreenNail implements ScreenNail { private static final int PLACEHOLDER_COLOR = 0xFF222222; // The duration of the fading animation in milliseconds private static final int DURATION = 180; + + private static final int MAX_SIDE = 640; + // These are special values for mAnimationStartTime private static final long ANIMATION_NOT_NEEDED = -1; private static final long ANIMATION_NEEDED = -2; @@ -44,7 +46,6 @@ public class BitmapScreenNail implements ScreenNail { private int mHeight; private Bitmap mBitmap; private BitmapTexture mTexture; - private FadeInTexture mFadeInTexture; private long mAnimationStartTime = ANIMATION_NOT_NEEDED; public BitmapScreenNail(Bitmap bitmap) { @@ -56,12 +57,17 @@ public class BitmapScreenNail implements ScreenNail { } public BitmapScreenNail(int width, int height) { + setSize(width, height); + } + + private void setSize(int width, int height) { if (width == 0 || height == 0) { width = 640; height = 480; } - mWidth = width; - mHeight = height; + float scale = Math.min(1, (float) MAX_SIDE / Math.max(width, height)); + mWidth = Math.round(scale * width); + mHeight = Math.round(scale * height); } // Combines the two ScreenNails. @@ -101,8 +107,7 @@ public class BitmapScreenNail implements ScreenNail { public void updatePlaceholderSize(int width, int height) { if (mBitmap != null) return; if (width == 0 || height == 0) return; - mWidth = width; - mHeight = height; + setSize(width, height); } @Override @@ -189,4 +194,8 @@ public class BitmapScreenNail implements ScreenNail { float r = (float)(now() - mAnimationStartTime) / DURATION; return Utils.clamp(1.0f - r, 0.0f, 1.0f); } + + public boolean isShowingPlaceholder() { + return (mBitmap == null) || isAnimating(); + } } diff --git a/src/com/android/gallery3d/ui/GLRootView.java b/src/com/android/gallery3d/ui/GLRootView.java index 987e9a2ae..8783b66bb 100644 --- a/src/com/android/gallery3d/ui/GLRootView.java +++ b/src/com/android/gallery3d/ui/GLRootView.java @@ -118,7 +118,7 @@ public class GLRootView extends GLSurfaceView getHolder().setFormat(PixelFormat.RGB_565); // Uncomment this to enable gl error check. - //setDebugFlags(DEBUG_CHECK_GL_ERROR); + // setDebugFlags(DEBUG_CHECK_GL_ERROR); } @Override diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java index fd08e0eb3..654fcd586 100644 --- a/src/com/android/gallery3d/ui/PhotoView.java +++ b/src/com/android/gallery3d/ui/PhotoView.java @@ -1334,7 +1334,10 @@ public class PhotoView extends GLView { MediaItem item = mModel.getMediaItem(i); if (item == null) continue; ScreenNail sc = mModel.getScreenNail(i); - if (sc == null) continue; + if (!(sc instanceof BitmapScreenNail) + || ((BitmapScreenNail) sc).isShowingPlaceholder()) continue; + + // Now, sc is BitmapScreenNail and is not showing placeholder Rect rect = new Rect(getPhotoRect(i)); if (!Rect.intersects(fullRect, rect)) continue; rect.offset(location.left, location.top); -- cgit v1.2.3