summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/PhotoModule.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/camera/PhotoModule.java')
-rw-r--r--src/com/android/camera/PhotoModule.java270
1 files changed, 30 insertions, 240 deletions
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index 30956c4e2..78fe8ee56 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -123,12 +123,7 @@ public class PhotoModule
private int mLongshotSnapNum = 0;
public boolean mFaceDetectionEnabled = false;
private boolean mLgeHdrMode = false;
- private DrawAutoHDR mDrawAutoHDR;
- /*Histogram variables*/
- private GraphView mGraphView;
- private static final int STATS_DATA = 257;
- public static int statsdata[] = new int[STATS_DATA];
- public boolean mHiston = false;
+ public boolean mHistogramEnabled = false;
// We number the request code from 1000 to avoid collision with Gallery.
private static final int REQUEST_CROP = 1000;
@@ -169,7 +164,6 @@ public class PhotoModule
private PhotoUI mUI;
- public boolean mAutoHdrEnable;
// The activity is going to switch to the specified camera id. This is
// needed because texture copy is done in GL thread. -1 means camera is not
// switching.
@@ -833,14 +827,6 @@ public class PhotoModule
}
mNamedImages = new NamedImages();
- mGraphView = (GraphView)mRootView.findViewById(R.id.graph_view);
- mDrawAutoHDR = (DrawAutoHDR )mRootView.findViewById(R.id.autohdr_view);
- if (mGraphView == null || mDrawAutoHDR == null){
- Log.e(TAG, "mGraphView or mDrawAutoHDR is null");
- } else{
- mGraphView.setPhotoModuleObject(this);
- mDrawAutoHDR.setPhotoModuleObject(this);
- }
mFirstTimeInitialized = true;
Log.d(TAG, "addIdleHandler in first time initialization");
@@ -1031,19 +1017,14 @@ public class PhotoModule
private final class StatsCallback
implements android.hardware.Camera.CameraDataCallback {
@Override
- public void onCameraData(int [] data, android.hardware.Camera camera) {
- //if(!mPreviewing || !mHiston || !mFirstTimeInitialized){
- if(!mHiston || !mFirstTimeInitialized){
+ public void onCameraData(final int [] data, android.hardware.Camera camera) {
+ if (!mHistogramEnabled || !mFirstTimeInitialized){
return;
}
- /*The first element in the array stores max hist value . Stats data begin from second value*/
- synchronized(statsdata) {
- System.arraycopy(data,0,statsdata,0,STATS_DATA);
- }
mActivity.runOnUiThread(new Runnable() {
+ @Override
public void run() {
- if(mGraphView != null)
- mGraphView.PreviewChanged();
+ mUI.updateHistogramData(data);
}
});
}
@@ -1058,24 +1039,13 @@ public class PhotoModule
for (int i =0;i<3;i++) {
metadata[i] = byteToInt( (byte []) data, i*4);
}
- if (metadata[2] == 1) {
- mAutoHdrEnable = true;
- mActivity.runOnUiThread(new Runnable() {
- public void run() {
- if (mDrawAutoHDR != null)
- mDrawAutoHDR.AutoHDR();
- }
- });
- }
- else {
- mAutoHdrEnable = false;
- mActivity.runOnUiThread(new Runnable() {
- public void run() {
- if (mDrawAutoHDR != null)
- mDrawAutoHDR.AutoHDR();
- }
- });
- }
+ final boolean autoHdrEnabled = metadata[2] == 1;
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mUI.setAutoHdrEnabled(autoHdrEnabled);
+ }
+ });
}
}
@@ -1401,16 +1371,14 @@ public class PhotoModule
mLongshotSnapNum = 0;
}
- if (mHiston && (mSnapshotMode ==CameraInfo.CAMERA_SUPPORT_MODE_ZSL)) {
+ if (mHistogramEnabled && (mSnapshotMode ==CameraInfo.CAMERA_SUPPORT_MODE_ZSL)) {
mActivity.runOnUiThread(new Runnable() {
- public void run() {
- if (mGraphView != null) {
- mGraphView.setVisibility(View.VISIBLE);
- mGraphView.PreviewChanged();
+ @Override
+ public void run() {
+ mUI.setHistogramEnabled(true, getCamera());
}
- }
- });
- }
+ });
+ }
if (mSnapshotMode == CameraInfo.CAMERA_SUPPORT_MODE_ZSL &&
mCameraState != LONGSHOT &&
mReceivedSnapNum == mBurstSnapNum &&
@@ -1544,15 +1512,15 @@ public class PhotoModule
mJpegImageData = null;
final boolean animateBefore = (mSceneMode == CameraUtil.SCENE_MODE_HDR);
- if(mHiston) {
+ if(mHistogramEnabled) {
if (mSnapshotMode != CameraInfo.CAMERA_SUPPORT_MODE_ZSL) {
- mHiston = false;
+ mHistogramEnabled = false;
mCameraDevice.setHistogramMode(null);
}
mActivity.runOnUiThread(new Runnable() {
+ @Override
public void run() {
- if(mGraphView != null)
- mGraphView.setVisibility(View.INVISIBLE);
+ mUI.setHistogramEnabled(false, null);
}
});
}
@@ -1946,9 +1914,6 @@ public class PhotoModule
mCameraDevice.setParameters(mParameters);
}
mUI.setOrientation(mOrientation, true);
- if (mGraphView != null) {
- mGraphView.setRotation(-mOrientation);
- }
}
// Show the toast after getting the first orientation changed.
@@ -1956,14 +1921,6 @@ public class PhotoModule
mHandler.removeMessages(SHOW_TAP_TO_FOCUS_TOAST);
showTapToFocusToast();
}
-
- // need to re-initialize mGraphView to show histogram on rotate
- mGraphView = (GraphView)mRootView.findViewById(R.id.graph_view);
- if(mGraphView != null){
- mGraphView.setAlpha(0.75f);
- mGraphView.setPhotoModuleObject(this);
- mGraphView.PreviewChanged();
- }
}
@Override
@@ -3172,26 +3129,9 @@ public class PhotoModule
if (CameraUtil.isAutoHDRSupported(mParameters)) {
mParameters.set("auto-hdr-enable",auto_hdr);
if (auto_hdr.equals("enable")) {
- mActivity.runOnUiThread(new Runnable() {
- public void run() {
- if (mDrawAutoHDR != null) {
- mDrawAutoHDR.setVisibility(View.VISIBLE);
- }
- }
- });
mParameters.setSceneMode("asd");
mCameraDevice.setMetadataCb(mMetaDataCallback);
}
- else {
- mAutoHdrEnable = false;
- mActivity.runOnUiThread( new Runnable() {
- public void run () {
- if (mDrawAutoHDR != null) {
- mDrawAutoHDR.setVisibility (View.INVISIBLE);
- }
- }
- });
- }
}
mParameters.setZSLMode(zsl);
if(zsl.equals("on")) {
@@ -3264,27 +3204,14 @@ public class PhotoModule
if (CameraUtil.isSupported(histogram,
mParameters.getSupportedHistogramModes()) && mCameraDevice != null) {
// Call for histogram
- if(histogram.equals("enable")) {
- mActivity.runOnUiThread(new Runnable() {
- public void run() {
- if(mGraphView != null) {
- mGraphView.setVisibility(View.VISIBLE);
- mGraphView.PreviewChanged();
- }
- }
- });
- mCameraDevice.setHistogramMode(mStatsCallback);
- mHiston = true;
- } else {
- mHiston = false;
- mActivity.runOnUiThread(new Runnable() {
- public void run() {
- if (mGraphView != null)
- mGraphView.setVisibility(View.INVISIBLE);
- }
- });
- mCameraDevice.setHistogramMode(null);
- }
+ mHistogramEnabled = histogram.equals("enable");
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mUI.setHistogramEnabled(mHistogramEnabled, getCamera());
+ }
+ });
+ mCameraDevice.setHistogramMode(mHistogramEnabled ? mStatsCallback : null);
}
setFlipValue();
@@ -4460,140 +4387,3 @@ public class PhotoModule
!mLongshotActive);
}
}
-
-class GraphView extends View {
- private Bitmap mBitmap;
- private Paint mPaint = new Paint();
- private Paint mPaintRect = new Paint();
- private Canvas mCanvas = new Canvas();
- private float mScale = (float)3;
- private float mWidth;
- private float mHeight;
- private PhotoModule mPhotoModule;
- private CameraManager.CameraProxy mGraphCameraDevice;
- private float scaled;
- private static final int STATS_SIZE = 256;
-
- public GraphView(Context context, AttributeSet attrs) {
- super(context,attrs);
-
- mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
- mPaintRect.setColor(0xFFFFFFFF);
- mPaintRect.setStyle(Paint.Style.FILL);
- }
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
- mCanvas.setBitmap(mBitmap);
- mWidth = w;
- mHeight = h;
- super.onSizeChanged(w, h, oldw, oldh);
- }
- @Override
- protected void onDraw(Canvas canvas) {
- if(mPhotoModule == null || !mPhotoModule.mHiston ) {
- return;
- }
-
- if (mBitmap != null) {
- final Paint paint = mPaint;
- final Canvas cavas = mCanvas;
- final float border = 5;
- float graphheight = mHeight - (2 * border);
- float graphwidth = mWidth - (2 * border);
- float left,top,right,bottom;
- float bargap = 0.0f;
- float barwidth = graphwidth/STATS_SIZE;
-
- cavas.drawColor(0xFFAAAAAA);
- paint.setColor(Color.BLACK);
-
- for (int k = 0; k <= (graphheight /32) ; k++) {
- float y = (float)(32 * k)+ border;
- cavas.drawLine(border, y, graphwidth + border , y, paint);
- }
- for (int j = 0; j <= (graphwidth /32); j++) {
- float x = (float)(32 * j)+ border;
- cavas.drawLine(x, border, x, graphheight + border, paint);
- }
- synchronized(PhotoModule.statsdata) {
- //Assumption: The first element contains
- // the maximum value.
- int maxValue = Integer.MIN_VALUE;
- if ( 0 == PhotoModule.statsdata[0] ) {
- for ( int i = 1 ; i <= STATS_SIZE ; i++ ) {
- if ( maxValue < PhotoModule.statsdata[i] ) {
- maxValue = PhotoModule.statsdata[i];
- }
- }
- } else {
- maxValue = PhotoModule.statsdata[0];
- }
- mScale = ( float ) maxValue;
- for(int i=1 ; i<=STATS_SIZE ; i++) {
- scaled = (PhotoModule.statsdata[i]/mScale)*STATS_SIZE;
- if(scaled >= (float)STATS_SIZE)
- scaled = (float)STATS_SIZE;
- left = (bargap * (i+1)) + (barwidth * i) + border;
- top = graphheight + border;
- right = left + barwidth;
- bottom = top - scaled;
- cavas.drawRect(left, top, right, bottom, mPaintRect);
- }
- }
- canvas.drawBitmap(mBitmap, 0, 0, null);
- }
- if (mPhotoModule.mHiston && mPhotoModule!= null) {
- mGraphCameraDevice = mPhotoModule.getCamera();
- if (mGraphCameraDevice != null){
- mGraphCameraDevice.sendHistogramData();
- }
- }
- }
- public void PreviewChanged() {
- invalidate();
- }
- public void setPhotoModuleObject(PhotoModule photoModule) {
- mPhotoModule = photoModule;
- }
-}
-
-class DrawAutoHDR extends View{
-
- private static final String TAG = "AutoHdrView";
- private PhotoModule mPhotoModule;
-
- public DrawAutoHDR (Context context, AttributeSet attrs) {
- super(context,attrs);
- }
-
- @Override
- protected void onDraw (Canvas canvas) {
- if (mPhotoModule == null)
- return;
- if (mPhotoModule.mAutoHdrEnable) {
- Paint AutoHDRPaint = new Paint();
- AutoHDRPaint.setColor(Color.WHITE);
- AutoHDRPaint.setAlpha (0);
- canvas.drawPaint(AutoHDRPaint);
- AutoHDRPaint.setStyle(Paint.Style.STROKE);
- AutoHDRPaint.setColor(Color.MAGENTA);
- AutoHDRPaint.setStrokeWidth(1);
- AutoHDRPaint.setTextSize(16);
- AutoHDRPaint.setAlpha (255);
- canvas.drawText("HDR On",200,100,AutoHDRPaint);
- }
- else {
- super.onDraw(canvas);
- return;
- }
- }
-
- public void AutoHDR () {
- invalidate();
- }
-
- public void setPhotoModuleObject (PhotoModule photoModule) {
- mPhotoModule = photoModule;
- }
-}