summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Yoo <jyoo@codeaurora.org>2016-01-27 17:09:15 -0800
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-05-26 09:48:45 -0700
commit02fa4483a6536b19ee49a5f98d30a3fa03eae72d (patch)
treec0afa86098ffd2f7f1452de45d092141cd66157a
parent94574eb97d43e17d0f2a115370f0f767f4c6049c (diff)
downloadandroid_packages_apps_Snap-02fa4483a6536b19ee49a5f98d30a3fa03eae72d.tar.gz
android_packages_apps_Snap-02fa4483a6536b19ee49a5f98d30a3fa03eae72d.tar.bz2
android_packages_apps_Snap-02fa4483a6536b19ee49a5f98d30a3fa03eae72d.zip
SnapdragonCamera: Fix the memory leak on view.
Keep using modules instead of creating. Don't remove the view without cleaning it. Change-Id: I260a660cac3d770f7d02dfdc1881e15490da66a0 CRs-Fixed: 958510
-rw-r--r--res/layout/camera.xml22
-rw-r--r--src/com/android/camera/CameraActivity.java77
-rw-r--r--src/com/android/camera/PhotoModule.java7
-rw-r--r--src/com/android/camera/PhotoUI.java5
-rw-r--r--src/com/android/camera/VideoModule.java7
-rw-r--r--src/com/android/camera/VideoUI.java6
-rw-r--r--src/com/android/camera/WideAnglePanoramaModule.java17
-rw-r--r--src/com/android/camera/WideAnglePanoramaUI.java4
-rw-r--r--src/com/android/camera/ui/CameraRootFrame.java44
9 files changed, 156 insertions, 33 deletions
diff --git a/res/layout/camera.xml b/res/layout/camera.xml
index 9a3a01a86..98b3a1013 100644
--- a/res/layout/camera.xml
+++ b/res/layout/camera.xml
@@ -13,9 +13,23 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<com.android.camera.ui.CameraRootView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/camera_app_root"
+<com.android.camera.ui.CameraRootFrame xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/camera_root_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
-</com.android.camera.ui.CameraRootView>
+ <com.android.camera.ui.CameraRootView
+ android:id="@+id/camera_photo_root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ </com.android.camera.ui.CameraRootView>
+ <com.android.camera.ui.CameraRootView
+ android:id="@+id/camera_video_root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ </com.android.camera.ui.CameraRootView>
+ <com.android.camera.ui.CameraRootView
+ android:id="@+id/camera_pano_root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ </com.android.camera.ui.CameraRootView>
+</com.android.camera.ui.CameraRootFrame>
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index 951cb072a..65b6065bf 100644
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -100,6 +100,7 @@ import com.android.camera.data.MediaDetails;
import com.android.camera.data.SimpleViewData;
import com.android.camera.exif.ExifInterface;
import com.android.camera.tinyplanet.TinyPlanetFragment;
+import com.android.camera.ui.CameraRootFrame;
import com.android.camera.ui.CameraRootView;
import com.android.camera.ui.ModuleSwitcher;
import com.android.camera.ui.DetailsDialog;
@@ -189,8 +190,14 @@ public class CameraActivity extends Activity
private PlaceholderManager mPlaceholderManager;
private int mCurrentModuleIndex;
private CameraModule mCurrentModule;
+ private PhotoModule mPhotoModule;
+ private VideoModule mVideoModule;
+ private WideAnglePanoramaModule mPanoModule;
private FrameLayout mAboveFilmstripControlLayout;
- private CameraRootView mCameraModuleRootView;
+ private CameraRootFrame mCameraRootFrame;
+ private CameraRootView mCameraPhotoModuleRootView;
+ private CameraRootView mCameraVideoModuleRootView;
+ private CameraRootView mCameraPanoModuleRootView;
private FilmStripView mFilmStripView;
private ProgressBar mBottomProgress;
private View mPanoStitchingPanel;
@@ -1440,7 +1447,12 @@ public class CameraActivity extends Activity
LayoutInflater inflater = getLayoutInflater();
View rootLayout = inflater.inflate(R.layout.camera, null, false);
- mCameraModuleRootView = (CameraRootView) rootLayout.findViewById(R.id.camera_app_root);
+ mCameraRootFrame = (CameraRootFrame)rootLayout.findViewById(R.id.camera_root_frame);
+ mCameraPhotoModuleRootView =
+ (CameraRootView)rootLayout.findViewById(R.id.camera_photo_root);
+ mCameraVideoModuleRootView =
+ (CameraRootView)rootLayout.findViewById(R.id.camera_video_root);
+ mCameraPanoModuleRootView = (CameraRootView)rootLayout.findViewById(R.id.camera_pano_root);
int moduleIndex = -1;
if (MediaStore.INTENT_ACTION_VIDEO_CAMERA.equals(getIntent().getAction())
@@ -1481,7 +1493,6 @@ public class CameraActivity extends Activity
mOrientationListener = new MyOrientationEventListener(this);
setModuleFromIndex(moduleIndex);
- mCurrentModule.init(this, mCameraModuleRootView);
mActionBar = getActionBar();
mActionBar.addOnMenuVisibilityListener(this);
@@ -1892,34 +1903,51 @@ public class CameraActivity extends Activity
* index an sets it as mCurrentModule.
*/
private void setModuleFromIndex(int moduleIndex) {
+ mCameraPhotoModuleRootView.setVisibility(View.GONE);
+ mCameraVideoModuleRootView.setVisibility(View.GONE);
+ mCameraPanoModuleRootView.setVisibility(View.GONE);
+ mCameraRootFrame.removeAllViews();
mCurrentModuleIndex = moduleIndex;
+
+ final CameraRootView rootView;
switch (moduleIndex) {
case ModuleSwitcher.VIDEO_MODULE_INDEX:
- mCurrentModule = new VideoModule();
- break;
-
- case ModuleSwitcher.PHOTO_MODULE_INDEX:
- mCurrentModule = new PhotoModule();
+ if (mVideoModule == null) {
+ mVideoModule = new VideoModule();
+ mVideoModule.init(this, mCameraVideoModuleRootView);
+ }
+ mCurrentModule = mVideoModule;
+ rootView = mCameraVideoModuleRootView;
break;
case ModuleSwitcher.WIDE_ANGLE_PANO_MODULE_INDEX:
- mCurrentModule = new WideAnglePanoramaModule();
+ if (mPanoModule == null) {
+ mPanoModule = new WideAnglePanoramaModule();
+ mPanoModule.init(this, mCameraPanoModuleRootView);
+ }
+ mCurrentModule = mPanoModule;
+ rootView = mCameraPanoModuleRootView;
break;
- 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();
- mCurrentModuleIndex = ModuleSwitcher.PHOTO_MODULE_INDEX;
+ case ModuleSwitcher.PHOTO_MODULE_INDEX:
+ case ModuleSwitcher.LIGHTCYCLE_MODULE_INDEX: //Unused module for now
+ case ModuleSwitcher.GCAM_MODULE_INDEX: //Unused module for now
+ default: // Fall back to photo mode.
+ if (mPhotoModule == null) {
+ mPhotoModule = new PhotoModule();
+ mPhotoModule.init(this, mCameraPhotoModuleRootView);
+ }
+ mCurrentModule = mPhotoModule;
+ rootView = mCameraPhotoModuleRootView;
break;
}
+ mCameraRootFrame.addView(rootView);
+ rootView.setVisibility(View.VISIBLE);
+
+ // Re-apply the last fitSystemWindows() run. Our views rely on this, but
+ // the framework's ActionBarOverlayLayout effectively prevents this if the
+ // actual insets haven't changed.
+ mCameraRootFrame.redoFitSystemWindows();
}
/**
@@ -1957,11 +1985,6 @@ public class CameraActivity extends Activity
}
private void openModule(CameraModule module) {
- module.init(this, mCameraModuleRootView);
- // Re-apply the last fitSystemWindows() run. Our views rely on this, but
- // the framework's ActionBarOverlayLayout effectively prevents this if the
- // actual insets haven't changed.
- mCameraModuleRootView.redoFitSystemWindows();
module.onResumeBeforeSuper();
module.onResumeAfterSuper();
}
@@ -1969,8 +1992,6 @@ public class CameraActivity extends Activity
private void closeModule(CameraModule module) {
module.onPauseBeforeSuper();
module.onPauseAfterSuper();
- ((ViewGroup) mCameraModuleRootView).removeAllViews();
- ((ViewGroup) mCameraModuleRootView).clearDisappearingChildren();
}
private void performDeletion() {
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index 67c2325f6..c2d00b562 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -2288,6 +2288,11 @@ public class PhotoModule
@Override
public void onResumeBeforeSuper() {
mPaused = false;
+ mPreferences = new ComboPreferences(mActivity);
+ CameraSettings.upgradeGlobalPreferences(mPreferences.getGlobal(), mActivity);
+ mCameraId = getPreferredCameraId(mPreferences);
+ mPreferences.setLocalId(mActivity, mCameraId);
+ CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());
}
private void openCamera() {
@@ -2334,6 +2339,7 @@ public class PhotoModule
Log.v(TAG, "On resume.");
onResumeTasks();
}
+ mUI.setSwitcherIndex();
mHandler.post(new Runnable(){
@Override
public void run(){
@@ -3021,6 +3027,7 @@ public class PhotoModule
if (CameraUtil.isSupported(colorEffect, mParameters.getSupportedColorEffects())) {
mParameters.setColorEffect(colorEffect);
}
+
//Set Saturation
String saturationStr = getSaturationSafe();
if (saturationStr != null) {
diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java
index ed3dd1c37..a7aebfb17 100644
--- a/src/com/android/camera/PhotoUI.java
+++ b/src/com/android/camera/PhotoUI.java
@@ -626,6 +626,11 @@ public class PhotoUI implements PieListener,
public void showSwitcher() {
mSwitcher.setVisibility(View.VISIBLE);
}
+
+ public void setSwitcherIndex() {
+ mSwitcher.setCurrentIndex(ModuleSwitcher.PHOTO_MODULE_INDEX);
+ }
+
// called from onResume but only the first time
public void initializeFirstTime() {
// Initialize shutter button.
diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java
index 356e25d77..85be83d9c 100644
--- a/src/com/android/camera/VideoModule.java
+++ b/src/com/android/camera/VideoModule.java
@@ -1120,6 +1120,11 @@ public class VideoModule implements CameraModule,
@Override
public void onResumeBeforeSuper() {
mPaused = false;
+ mPreferences = new ComboPreferences(mActivity);
+ CameraSettings.upgradeGlobalPreferences(mPreferences.getGlobal(), mActivity);
+ mCameraId = getPreferredCameraId(mPreferences);
+ mPreferences.setLocalId(mActivity, mCameraId);
+ CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());
}
@Override
@@ -1128,6 +1133,7 @@ public class VideoModule implements CameraModule,
mZoomValue = 0;
resetExposureCompensation();
+ initializeVideoControl();
showVideoSnapshotUI(false);
if (!mPreviewing) {
@@ -1147,6 +1153,7 @@ public class VideoModule implements CameraModule,
// Initializing it here after the preview is started.
mUI.initializeZoom(mParameters);
mUI.setPreviewGesturesVideoUI();
+ mUI.setSwitcherIndex();
keepScreenOnAwhile();
mOrientationManager.resume();
diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java
index c28fcca82..65f27a334 100644
--- a/src/com/android/camera/VideoUI.java
+++ b/src/com/android/camera/VideoUI.java
@@ -331,7 +331,7 @@ public class VideoUI implements PieRenderer.PieListener,
}
mCameraControls.setPreviewRatio(mAspectRatio, false);
- layoutPreview((float)ratio);
+ layoutPreview((float) ratio);
}
private void layoutPreview(float ratio) {
@@ -487,6 +487,10 @@ public class VideoUI implements PieRenderer.PieListener,
mSwitcher.setVisibility(View.VISIBLE);
}
+ public void setSwitcherIndex() {
+ mSwitcher.setCurrentIndex(ModuleSwitcher.VIDEO_MODULE_INDEX);
+ }
+
public boolean collapseCameraControls() {
boolean ret = false;
mSwitcher.closePopup();
diff --git a/src/com/android/camera/WideAnglePanoramaModule.java b/src/com/android/camera/WideAnglePanoramaModule.java
index e8ef589d7..0f1396a7d 100644
--- a/src/com/android/camera/WideAnglePanoramaModule.java
+++ b/src/com/android/camera/WideAnglePanoramaModule.java
@@ -215,6 +215,17 @@ public class WideAnglePanoramaModule
}
}
+ private int getPreferredCameraId(ComboPreferences preferences) {
+ int intentCameraId = CameraUtil.getCameraFacingIntentExtras(mActivity);
+ if (intentCameraId != -1) {
+ // Testing purpose. Launch a specific camera through the intent
+ // extras.
+ return intentCameraId;
+ } else {
+ return CameraSettings.readPreferredCameraId(preferences);
+ }
+ }
+
@Override
public void init(CameraActivity activity, View parent) {
mActivity = activity;
@@ -291,6 +302,7 @@ public class WideAnglePanoramaModule
mDialogWaitingPreviousString = appRes.getString(R.string.pano_dialog_waiting_previous);
mPreferences = new ComboPreferences(mActivity);
+ mPreferences.setLocalId(mActivity, getPreferredCameraId(mPreferences));
CameraSettings.upgradeGlobalPreferences(mPreferences.getGlobal(), activity);
mLocationManager = new LocationManager(mActivity, null);
@@ -951,6 +963,10 @@ public class WideAnglePanoramaModule
@Override
public void onResumeBeforeSuper() {
mPaused = false;
+ mPreferences = new ComboPreferences(mActivity);
+ CameraSettings.upgradeGlobalPreferences(mPreferences.getGlobal(), mActivity);
+ mPreferences.setLocalId(mActivity, getPreferredCameraId(mPreferences));
+ CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());
}
@Override
@@ -992,6 +1008,7 @@ public class WideAnglePanoramaModule
}
});
}
+ mUI.setSwitcherIndex();
keepScreenOnAwhile();
mOrientationManager.resume();
diff --git a/src/com/android/camera/WideAnglePanoramaUI.java b/src/com/android/camera/WideAnglePanoramaUI.java
index 3c55adda7..37a476f48 100644
--- a/src/com/android/camera/WideAnglePanoramaUI.java
+++ b/src/com/android/camera/WideAnglePanoramaUI.java
@@ -187,6 +187,10 @@ public class WideAnglePanoramaUI implements
mSwitcher.setVisibility(View.VISIBLE);
}
+ public void setSwitcherIndex() {
+ mSwitcher.setCurrentIndex(ModuleSwitcher.WIDE_ANGLE_PANO_MODULE_INDEX);
+ }
+
public void setCaptureProgressOnDirectionChangeListener(
PanoProgressBar.OnDirectionChangeListener listener) {
mCaptureProgressBar.setOnDirectionChangeListener(listener);
diff --git a/src/com/android/camera/ui/CameraRootFrame.java b/src/com/android/camera/ui/CameraRootFrame.java
new file mode 100644
index 000000000..d9464ad90
--- /dev/null
+++ b/src/com/android/camera/ui/CameraRootFrame.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2013 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.camera.ui;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.util.AttributeSet;
+import android.widget.FrameLayout;
+
+public class CameraRootFrame extends FrameLayout {
+ private Rect mLastInsets = new Rect();
+
+ public CameraRootFrame(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public void redoFitSystemWindows() {
+ if (mLastInsets.left != 0 || mLastInsets.right != 0
+ || mLastInsets.top != 0 || mLastInsets.bottom != 0) {
+ Rect insets = new Rect(mLastInsets);
+ fitSystemWindows(insets);
+ }
+ }
+
+ @Override
+ protected boolean fitSystemWindows(Rect insets) {
+ mLastInsets.set(insets);
+ return super.fitSystemWindows(insets);
+ }
+}