summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2016-11-17 20:38:43 -0800
committerSteve Kondik <steve@cyngn.com>2016-11-17 23:55:07 -0800
commit76b587ca3d957127f38df5fe599808b94a0b08c3 (patch)
tree83de8965d8349afe737d7e18d4dd1bb67a7cd084 /src/com
parent1041bf671160d85995cf1950aba5d2187a414569 (diff)
downloadandroid_packages_apps_Snap-76b587ca3d957127f38df5fe599808b94a0b08c3.tar.gz
android_packages_apps_Snap-76b587ca3d957127f38df5fe599808b94a0b08c3.tar.bz2
android_packages_apps_Snap-76b587ca3d957127f38df5fe599808b94a0b08c3.zip
snap: Improve the histogram
* Make it work with the new UI * Make it pretty Change-Id: Ib920307639f997c82ed003e0712fb28e9912a8e8
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/camera/PhotoModule.java1
-rw-r--r--src/com/android/camera/ui/CameraControls.java13
-rw-r--r--src/com/android/camera/ui/HistogramView.java94
3 files changed, 69 insertions, 39 deletions
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index ed7ad8da2..6883a3624 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -3683,6 +3683,7 @@ public class PhotoModule extends BaseModule<PhotoUI> implements
}
});
mCameraDevice.setHistogramMode(mHistogramEnabled ? mStatsCallback : null);
+ mParameters.set("histogram", histogram);
}
setFlipValue();
diff --git a/src/com/android/camera/ui/CameraControls.java b/src/com/android/camera/ui/CameraControls.java
index 9102db3c3..9d023bbe9 100644
--- a/src/com/android/camera/ui/CameraControls.java
+++ b/src/com/android/camera/ui/CameraControls.java
@@ -145,6 +145,10 @@ public class CameraControls extends RotatableLayout {
}
}
+ if (mHistogramView.getVisibility() != View.GONE) {
+ mHistogramView.setVisibility(enable ? View.VISIBLE : View.INVISIBLE);
+ }
+
((ShutterButton) mShutter).enableTouch(enable);
mVideoShutter.setClickable(enable);
mTopBar.setEnabled(enable);
@@ -290,8 +294,11 @@ public class CameraControls extends RotatableLayout {
mAutoHdrNotice.layout(l, t + mTopMargin,
r, t + mTopMargin + mAutoHdrNotice.getMeasuredHeight());
- mHistogramView.layout(l, b - mBottomMargin - mHistogramView.getMeasuredHeight(),
- r, b - mBottomMargin);
+ int hw = getResources().getDimensionPixelSize(R.dimen.histogram_width);
+ int hh = getResources().getDimensionPixelSize(R.dimen.histogram_height);
+
+ mHistogramView.layout(r - hw, b - mBottomMargin - hh - 4,
+ r, b - mBottomMargin - 4);
View retake = findViewById(R.id.btn_retake);
if (retake != null) {
@@ -478,7 +485,7 @@ public class CameraControls extends RotatableLayout {
if (v instanceof RotateImageView) {
((RotateImageView) v).setOrientation(orientation, animation);
} else if (v instanceof HistogramView) {
- ((HistogramView) v).setRotation(-orientation);
+ ((HistogramView) v).setOrientation(orientation);
}
}
}
diff --git a/src/com/android/camera/ui/HistogramView.java b/src/com/android/camera/ui/HistogramView.java
index 2ae2c40a8..11a4bb43b 100644
--- a/src/com/android/camera/ui/HistogramView.java
+++ b/src/com/android/camera/ui/HistogramView.java
@@ -22,31 +22,38 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
+import android.graphics.PorterDuff;
import android.util.AttributeSet;
+import android.util.MathUtils;
import android.view.View;
import com.android.camera.CameraManager;
+import org.codeaurora.snapcam.R;
+
public class HistogramView extends View {
+ private static final String TAG = "CAM_" + HistogramView.class.getSimpleName();
+
private static final int STATS_SIZE = 256;
+ private static final int CELL_COUNT = 64;
private int[] mData = new int[STATS_SIZE + 1];
private boolean mDataValid;
- private Bitmap mBitmap;
- private Paint mPaint = new Paint();
- private Paint mPaintRect = new Paint();
- private Canvas mCanvas = new Canvas();
- private float mWidth;
- private float mHeight;
+ private Bitmap mBitmap;
+ private Paint mPaint = new Paint();
+ private Paint mPaintRect = new Paint();
+ private Canvas mCanvas = new Canvas();
+ private float mWidth;
+ private float mHeight;
private CameraManager.CameraProxy mGraphCameraDevice;
public HistogramView(Context context, AttributeSet attrs) {
- super(context,attrs);
+ super(context, attrs);
mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
- mPaintRect.setColor(0xFFFFFFFF);
- mPaintRect.setStyle(Paint.Style.FILL);
+
+ setWillNotDraw(false);
}
public void setCamera(CameraManager.CameraProxy camera) {
@@ -67,7 +74,7 @@ public class HistogramView extends View {
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
+ mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
mCanvas.setBitmap(mBitmap);
mWidth = w;
mHeight = h;
@@ -87,43 +94,58 @@ public class HistogramView extends View {
}
}
- private void drawGraph() {
- final float border = 5;
- float graphheight = mHeight - (2 * border);
- float graphwidth = mWidth - (2 * border);
- float bargap = 0.0f;
- float barwidth = graphwidth/STATS_SIZE;
-
- mCanvas.drawColor(0xFFAAAAAA);
- mPaint.setColor(Color.BLACK);
-
- for (int k = 0; k <= (graphheight /32) ; k++) {
- float y = (float)(32 * k)+ border;
- mCanvas.drawLine(border, y, graphwidth + border , y, mPaint);
- }
- for (int j = 0; j <= (graphwidth /32); j++) {
- float x = (float)(32 * j)+ border;
- mCanvas.drawLine(x, border, x, graphheight + border, mPaint);
+ public void setOrientation(int orientation) {
+ setRotation(-orientation);
+ int top = getContext().getResources().getDimensionPixelSize(R.dimen.preview_top_margin);
+
+ if (orientation == 0 || orientation == 180) {
+ setTranslationX(0);
+ setTranslationY(0);
+ } else {
+ setTranslationX(mHeight / 2);
+ setTranslationY(-(top / 2));
}
+ }
+
+ private void drawGraph() {
+ float padding = 10;
+ float height = mHeight - (padding * 2);
+ float width = mWidth - (padding * 2);
+ int cellWidth = Math.round(width / CELL_COUNT);
+
+
+ mCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
+
+ mPaintRect.setColor(Color.WHITE);
//Assumption: The first element contains the maximum value.
int maxValue = Integer.MIN_VALUE;
if (mData[0] == 0) {
- for (int i = 1; i <= STATS_SIZE ; i++) {
+ for (int i = 1; i <= STATS_SIZE; i++) {
maxValue = Math.max(maxValue, mData[i]);
}
} else {
maxValue = mData[0];
}
- for (int i = 1; i <= STATS_SIZE; i++) {
- float scaled = Math.min(STATS_SIZE,
- (float) mData[i] * (float) STATS_SIZE / (float) maxValue);
- float left = (bargap * (i+1)) + (barwidth * i) + border;
- float top = graphheight + border;
- float right = left + barwidth;
- float bottom = top - scaled;
- mCanvas.drawRect(left, top, right, bottom, mPaintRect);
+ int[] values = new int[CELL_COUNT];
+ int cell = 0;
+ float sum = 0.0f;
+ for (int i = 1; i < STATS_SIZE; i++) {
+ sum += (float) mData[i] / (float) maxValue;
+ if ((i % cellWidth) == 0) {
+ float mean = sum / cellWidth;
+ int value = Math.round(MathUtils.lerp(0, height, mean));
+ values[cell] = value;
+
+ float left = padding + (cell * cellWidth);
+ float right = left + cellWidth - 2;
+ float bottom = mHeight - (padding / 2);
+ float top = bottom - value;
+ mCanvas.drawRect(left, top, right, bottom, mPaintRect);
+ sum = 0.0f;
+ cell++;
+ }
}
}
}