diff options
author | Bobby Georgescu <georgescu@google.com> | 2012-12-03 13:56:00 -0800 |
---|---|---|
committer | Bobby Georgescu <georgescu@google.com> | 2012-12-03 16:15:54 -0800 |
commit | a2d0d34a90543ee19ea295e72c112fde18fb3828 (patch) | |
tree | ff18742ea6769f015011b99d3ac425fd988c707f /src/com/android/gallery3d/app/AbstractGalleryActivity.java | |
parent | eb3948f488b38bf5e6232c1aada16115589b0b9b (diff) | |
download | android_packages_apps_Gallery2-a2d0d34a90543ee19ea295e72c112fde18fb3828.tar.gz android_packages_apps_Gallery2-a2d0d34a90543ee19ea295e72c112fde18fb3828.tar.bz2 android_packages_apps_Gallery2-a2d0d34a90543ee19ea295e72c112fde18fb3828.zip |
Move MenuExecutor operations into Service
Bug: 6680729
Change-Id: I538bb0a8783f7c1ff467ba8d8eb0deefdc0b6ea2
Diffstat (limited to 'src/com/android/gallery3d/app/AbstractGalleryActivity.java')
-rw-r--r-- | src/com/android/gallery3d/app/AbstractGalleryActivity.java | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/com/android/gallery3d/app/AbstractGalleryActivity.java b/src/com/android/gallery3d/app/AbstractGalleryActivity.java index 8f824cfd2..081b87aee 100644 --- a/src/com/android/gallery3d/app/AbstractGalleryActivity.java +++ b/src/com/android/gallery3d/app/AbstractGalleryActivity.java @@ -19,14 +19,17 @@ package com.android.gallery3d.app; import android.annotation.TargetApi; import android.app.AlertDialog; import android.content.BroadcastReceiver; +import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.IntentFilter; +import android.content.ServiceConnection; import android.content.res.Configuration; import android.os.Bundle; +import android.os.IBinder; import android.view.Window; import android.view.WindowManager; @@ -40,8 +43,8 @@ import com.android.gallery3d.data.DataManager; import com.android.gallery3d.data.MediaItem; import com.android.gallery3d.ui.GLRoot; import com.android.gallery3d.ui.GLRootView; -import com.android.gallery3d.util.ThreadPool; import com.android.gallery3d.util.LightCycleHelper.PanoramaViewHelper; +import com.android.gallery3d.util.ThreadPool; public class AbstractGalleryActivity extends SherlockActivity implements GalleryContext { @SuppressWarnings("unused") @@ -71,6 +74,7 @@ public class AbstractGalleryActivity extends SherlockActivity implements Gallery getWindow().setBackgroundDrawable(null); mPanoramaViewHelper = new PanoramaViewHelper(this); mPanoramaViewHelper.onCreate(); + doBindBatchService(); } @Override @@ -237,6 +241,7 @@ public class AbstractGalleryActivity extends SherlockActivity implements Gallery } finally { mGLRootView.unlockRenderThread(); } + doUnbindBatchService(); } @Override @@ -308,4 +313,39 @@ public class AbstractGalleryActivity extends SherlockActivity implements Gallery return (getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; } + + private BatchService mBatchService; + private boolean mBatchServiceIsBound = false; + private ServiceConnection mBatchServiceConnection = new ServiceConnection() { + public void onServiceConnected(ComponentName className, IBinder service) { + mBatchService = ((BatchService.LocalBinder)service).getService(); + } + + public void onServiceDisconnected(ComponentName className) { + mBatchService = null; + } + }; + + private void doBindBatchService() { + bindService(new Intent(this, BatchService.class), mBatchServiceConnection, Context.BIND_AUTO_CREATE); + mBatchServiceIsBound = true; + } + + private void doUnbindBatchService() { + if (mBatchServiceIsBound) { + // Detach our existing connection. + unbindService(mBatchServiceConnection); + mBatchServiceIsBound = false; + } + } + + public ThreadPool getBatchServiceThreadPoolIfAvailable() { + if (mBatchServiceIsBound && mBatchService != null) { + return mBatchService.getThreadPool(); + } else { + // Fall back on the old behavior if for some reason the + // service is not available. + return getThreadPool(); + } + } } |