From a9d66bdab247626b31dc182c4d62520b3abffdbd Mon Sep 17 00:00:00 2001 From: Ruben Brunk Date: Fri, 6 Sep 2013 11:56:32 -0700 Subject: Adding gcam module to Camera2 app. Bug: 10430748 Change-Id: I0c53085553cd8505ba376b1518507d36065894f5 --- src/com/android/camera/CameraActivity.java | 10 ++++-- src/com/android/camera/CameraHolder.java | 6 ++++ src/com/android/camera/MediaSaveService.java | 2 +- src/com/android/camera/PhotoModule.java | 47 +++++++++++++-------------- src/com/android/camera/ui/ModuleSwitcher.java | 15 +++++++++ 5 files changed, 52 insertions(+), 28 deletions(-) (limited to 'src/com') diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java index 46dc2ba1e..d733964d7 100644 --- a/src/com/android/camera/CameraActivity.java +++ b/src/com/android/camera/CameraActivity.java @@ -71,6 +71,7 @@ import com.android.camera.ui.DetailsDialog; import com.android.camera.ui.FilmStripView; import com.android.camera.util.ApiHelper; import com.android.camera.util.CameraUtil; +import com.android.camera.util.GcamHelper; import com.android.camera.util.PhotoSphereHelper; import com.android.camera.util.PhotoSphereHelper.PanoramaViewHelper; import com.android.camera2.R; @@ -838,7 +839,8 @@ public class CameraActivity extends Activity // 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) { + if ((moduleIndex == ModuleSwitcher.GCAM_MODULE_INDEX && + !GcamHelper.hasGcamCapture(this)) || moduleIndex < 0) { moduleIndex = ModuleSwitcher.PHOTO_MODULE_INDEX; } } @@ -1141,7 +1143,11 @@ public class CameraActivity extends Activity case ModuleSwitcher.LIGHTCYCLE_MODULE_INDEX: mCurrentModule = PhotoSphereHelper.createPanoramaModule(); break; - + case ModuleSwitcher.GCAM_MODULE_INDEX: + // Force immediate release of Camera instance + CameraHolder.instance().strongRelease(); + mCurrentModule = GcamHelper.createGcamModule(); + break; default: // Fall back to photo mode. mCurrentModule = new PhotoModule(); diff --git a/src/com/android/camera/CameraHolder.java b/src/com/android/camera/CameraHolder.java index 32eae8289..e3f2c11e7 100644 --- a/src/com/android/camera/CameraHolder.java +++ b/src/com/android/camera/CameraHolder.java @@ -262,6 +262,12 @@ public class CameraHolder { mKeepBeforeTime - now); return; } + strongRelease(); + } + + public synchronized void strongRelease() { + if (mCameraDevice == null) return; + mCameraOpened = false; mCameraDevice.release(); mCameraDevice = null; diff --git a/src/com/android/camera/MediaSaveService.java b/src/com/android/camera/MediaSaveService.java index 9c42a5c07..e8ec08d57 100644 --- a/src/com/android/camera/MediaSaveService.java +++ b/src/com/android/camera/MediaSaveService.java @@ -48,7 +48,7 @@ public class MediaSaveService extends Service { // Memory used by the total queued save request, in bytes. private long mMemoryUse; - interface Listener { + public interface Listener { public void onQueueStatus(boolean full); } diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index 861dead2d..150b6e822 100644 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -57,6 +57,7 @@ import com.android.camera.CameraManager.CameraAFMoveCallback; import com.android.camera.CameraManager.CameraPictureCallback; import com.android.camera.CameraManager.CameraProxy; import com.android.camera.CameraManager.CameraShutterCallback; +import com.android.camera.PhotoModule.NamedImages.NamedEntity; import com.android.camera.exif.ExifInterface; import com.android.camera.exif.ExifTag; import com.android.camera.exif.Rational; @@ -75,6 +76,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; +import java.util.Vector; public class PhotoModule implements CameraModule, @@ -721,8 +723,9 @@ public class PhotoModule width = s.height; height = s.width; } - String title = mNamedImages.getTitle(); - long date = mNamedImages.getDate(); + NamedEntity name = mNamedImages.getNextNameEntity(); + String title = (name == null) ? null : name.title; + long date = (name == null) ? -1 : name.date; if (title == null) { Log.e(TAG, "Unbalanced name/data pair"); } else { @@ -790,41 +793,35 @@ public class PhotoModule } } - private static class NamedImages { - private ArrayList mQueue; - private NamedEntity mNamedEntity; + /** + * This class is just a thread-safe queue for name,date holder objects. + */ + public static class NamedImages { + private Vector mQueue; public NamedImages() { - mQueue = new ArrayList(); + mQueue = new Vector(); } - public void nameNewImage(ContentResolver resolver, long date) { + public void nameNewImage(long date) { NamedEntity r = new NamedEntity(); r.title = CameraUtil.createJpegName(date); r.date = date; mQueue.add(r); } - public String getTitle() { - if (mQueue.isEmpty()) { - mNamedEntity = null; - return null; + public NamedEntity getNextNameEntity() { + synchronized(mQueue) { + if (!mQueue.isEmpty()) { + return mQueue.remove(0); + } } - mNamedEntity = mQueue.get(0); - mQueue.remove(0); - - return mNamedEntity.title; - } - - // Must be called after getTitle(). - public long getDate() { - if (mNamedEntity == null) return -1; - return mNamedEntity.date; + return null; } - private static class NamedEntity { - String title; - long date; + public static class NamedEntity { + public String title; + public long date; } } @@ -893,7 +890,7 @@ public class PhotoModule mRawPictureCallback, mPostViewPictureCallback, new JpegPictureCallback(loc)); - mNamedImages.nameNewImage(mContentResolver, mCaptureStartTime); + mNamedImages.nameNewImage(mCaptureStartTime); mFaceDetectionStarted = false; setCameraState(SNAPSHOT_IN_PROGRESS); diff --git a/src/com/android/camera/ui/ModuleSwitcher.java b/src/com/android/camera/ui/ModuleSwitcher.java index 69ae3b57e..882f6c931 100644 --- a/src/com/android/camera/ui/ModuleSwitcher.java +++ b/src/com/android/camera/ui/ModuleSwitcher.java @@ -35,6 +35,7 @@ import android.widget.FrameLayout.LayoutParams; import android.widget.LinearLayout; import com.android.camera.util.CameraUtil; +import com.android.camera.util.GcamHelper; import com.android.camera.util.PhotoSphereHelper; import com.android.camera.util.UsageStatistics; import com.android.camera2.R; @@ -50,11 +51,14 @@ public class ModuleSwitcher extends RotateImageView public static final int VIDEO_MODULE_INDEX = 1; public static final int WIDE_ANGLE_PANO_MODULE_INDEX = 2; public static final int LIGHTCYCLE_MODULE_INDEX = 3; + public static final int GCAM_MODULE_INDEX = 4; + private static final int[] DRAW_IDS = { R.drawable.ic_switch_camera, R.drawable.ic_switch_video, R.drawable.ic_switch_pan, R.drawable.ic_switch_photosphere, + R.drawable.ic_switch_gcam, }; public interface ModuleSwitchListener { @@ -104,6 +108,10 @@ public class ModuleSwitcher extends RotateImageView --numDrawIds; } + if (!GcamHelper.hasGcamCapture(context)) { + --numDrawIds; + } + int[] drawids = new int[numDrawIds]; int[] moduleids = new int[numDrawIds]; int ix = 0; @@ -111,6 +119,9 @@ public class ModuleSwitcher extends RotateImageView if (i == LIGHTCYCLE_MODULE_INDEX && !PhotoSphereHelper.hasLightCycleCapture(context)) { continue; // not enabled, so don't add to UI } + if (i == GCAM_MODULE_INDEX && !GcamHelper.hasGcamCapture(context)) { + continue; // not enabled, so don't add to UI + } moduleids[ix] = i; drawids[ix++] = DRAW_IDS[i]; } @@ -200,6 +211,10 @@ public class ModuleSwitcher extends RotateImageView item.setContentDescription(getContext().getResources().getString( R.string.accessibility_switch_to_photo_sphere)); break; + case R.drawable.ic_switch_gcam: + item.setContentDescription(getContext().getResources().getString( + R.string.accessibility_switch_to_gcam)); + break; default: break; } -- cgit v1.2.3