Merge "Fix to prevent auto-thumbnailer to run on images whose decoding has failed (causing CPU cycles being wasted resulting in sometimes affecting performance of CPU intensive applications such as the video player)" into eclair
diff --git a/src/com/cooliris/media/Gallery.java b/src/com/cooliris/media/Gallery.java
index ee7f9c3..0ea80dd 100644
--- a/src/com/cooliris/media/Gallery.java
+++ b/src/com/cooliris/media/Gallery.java
@@ -42,6 +42,7 @@
     private MediaScannerConnection mConnection;
     private WakeLock mWakeLock;
     private HashMap<String, Boolean> mAccountsEnabled = new HashMap<String, Boolean>();
+    private boolean mDockSlideshow = false;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -60,12 +61,10 @@
                 Toast.makeText(this, getResources().getString(R.string.no_sd_card), Toast.LENGTH_LONG).show();
                 finish();
             } else {
-                PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
-                mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "GridView.Slideshow.All");
-                mWakeLock.acquire();
                 Slideshow slideshow = new Slideshow(this);
                 slideshow.setDataSource(new RandomDataSource());
                 setContentView(slideshow);
+                mDockSlideshow = true;
             }
             return;
         }
@@ -190,6 +189,17 @@
     @Override
     public void onResume() {
         super.onResume();
+        if (mDockSlideshow) {
+            if (mWakeLock != null) {
+                if (mWakeLock.isHeld()) {
+                    mWakeLock.release();
+                }
+            }
+            PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+            mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "GridView.Slideshow.All");
+            mWakeLock.acquire();
+            return;
+        }
         if (ImageManager.hasStorage()) {
             CacheService.computeDirtySets(this);
             CacheService.startCache(this, false);
@@ -229,6 +239,12 @@
         super.onPause();
         if (mRenderView != null)
             mRenderView.onPause();
+        if (mWakeLock != null) {
+            if (mWakeLock.isHeld()) {
+                mWakeLock.release();
+            }
+            mWakeLock = null;
+        }
         mPause = true;
     }
 
@@ -261,12 +277,6 @@
             }
             mGridLayer.shutdown();
         }
-        if (mWakeLock != null) {
-            if (mWakeLock.isHeld()) {
-                mWakeLock.release();
-            }
-            mWakeLock = null;
-        }
         if (mReverseGeocoder != null)
             mReverseGeocoder.shutdown();
         if (mRenderView != null) {