summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2016-03-25 13:12:21 +0100
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-03-29 00:18:36 -0700
commit6611f21d1fb9fecaf8dfc12ade9fa1e861cb57e2 (patch)
tree33a517ccd03ead6c49b9a044ef6de269b3b76d3d
parentbf93e1b5207dd9286143624af4fe90af21c2e0d4 (diff)
downloadandroid_packages_apps_Snap-6611f21d1fb9fecaf8dfc12ade9fa1e861cb57e2.tar.gz
android_packages_apps_Snap-6611f21d1fb9fecaf8dfc12ade9fa1e861cb57e2.tar.bz2
android_packages_apps_Snap-6611f21d1fb9fecaf8dfc12ade9fa1e861cb57e2.zip
Beautify and optimize histogram view.
Make it semi-transparent, draw a predictable number of grid lines and drop the unneeded drawing to a bitmap. Change-Id: I07e3cb8507f5bebbd06730ccc28acb8053bc1d1a
-rw-r--r--res/layout-port/camera_controls.xml1
-rw-r--r--res/values/colors.xml3
-rw-r--r--src/com/android/camera/ui/HistogramView.java126
3 files changed, 67 insertions, 63 deletions
diff --git a/res/layout-port/camera_controls.xml b/res/layout-port/camera_controls.xml
index bb73cf3c5..5b92db021 100644
--- a/res/layout-port/camera_controls.xml
+++ b/res/layout-port/camera_controls.xml
@@ -103,6 +103,7 @@
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_marginTop="20dip"
+ android:padding="2dp"
android:visibility="gone" />
<TextView
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 4fdc3e3f9..90694bc6e 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -78,6 +78,7 @@
<color name="camera_control_bg_opaque">@color/black</color>
<color name="camera_control_bg_transparent">#40212121</color>
-
+ <color name="histogram_grid_lines">#c0bdbdbd</color>
+ <color name="histogram_bars">#e0ffffff</color>
<color name="toast_text">@color/white</color>
</resources>
diff --git a/src/com/android/camera/ui/HistogramView.java b/src/com/android/camera/ui/HistogramView.java
index 2ae2c40a8..822233c2b 100644
--- a/src/com/android/camera/ui/HistogramView.java
+++ b/src/com/android/camera/ui/HistogramView.java
@@ -18,7 +18,7 @@
package com.android.camera.ui;
import android.content.Context;
-import android.graphics.Bitmap;
+import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@@ -26,27 +26,33 @@ import android.util.AttributeSet;
import android.view.View;
import com.android.camera.CameraManager;
+import org.codeaurora.snapcam.R;
public class HistogramView extends View {
private static final int STATS_SIZE = 256;
+ private static final int GRID_LINES = 10;
- private int[] mData = new int[STATS_SIZE + 1];
+ private float[] mData = new float[STATS_SIZE];
+ private int mMaxDataValue;
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 int mBgColor;
+ private int mBarColor;
+ private int mGridColor;
+
+ private Paint mPaint = new Paint();
private CameraManager.CameraProxy mGraphCameraDevice;
public HistogramView(Context context, AttributeSet attrs) {
super(context,attrs);
- mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
- mPaintRect.setColor(0xFFFFFFFF);
- mPaintRect.setStyle(Paint.Style.FILL);
+ Resources res = context.getResources();
+ mBgColor = res.getColor(R.color.camera_control_bg_transparent);
+ mBarColor = res.getColor(R.color.histogram_bars);
+ mGridColor = res.getColor(R.color.histogram_grid_lines);
+
+ mPaint.setAntiAlias(true);
+ mPaint.setStyle(Paint.Style.FILL);
}
public void setCamera(CameraManager.CameraProxy camera) {
@@ -57,73 +63,69 @@ public class HistogramView extends View {
}
public void updateData(int[] data) {
- if (data.length == mData.length) {
- System.arraycopy(data, 0, mData, 0, data.length);
- drawGraph();
- mDataValid = true;
- invalidate();
+ if (data.length != STATS_SIZE + 1) {
+ return;
}
- }
- @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;
- if (mDataValid) {
- drawGraph();
+ int maxValue;
+ //Assumption: The first element contains the maximum value.
+ if (data[0] == 0) {
+ maxValue = Integer.MIN_VALUE;
+ for (int i = 1; i <= STATS_SIZE ; i++) {
+ maxValue = Math.max(maxValue, data[i]);
+ }
+ } else {
+ maxValue = data[0];
}
- super.onSizeChanged(w, h, oldw, oldh);
+
+ // mData = data scaled by maxValue
+ for (int i = 0; i < STATS_SIZE; i++) {
+ mData[i] = Math.min((float) data[i + 1] / (float) maxValue, 1.0F);
+ }
+ mDataValid = true;
+ invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
- if (mDataValid && mBitmap != null) {
- canvas.drawBitmap(mBitmap, 0, 0, null);
- if (mGraphCameraDevice != null) {
- mGraphCameraDevice.sendHistogramData();
- }
+ if (!mDataValid) {
+ return;
}
- }
- 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;
+ final int paddingLeft = getPaddingLeft();
+ final int paddingRight = getPaddingRight();
+ final int paddingTop = getPaddingTop();
+ final int paddingBottom = getPaddingBottom();
+
+ float graphWidth = getWidth() - paddingLeft - paddingRight;
+ float graphHeight = getHeight() - paddingTop - paddingBottom;
+ float barWidth = graphWidth / STATS_SIZE;
- mCanvas.drawColor(0xFFAAAAAA);
- mPaint.setColor(Color.BLACK);
+ mPaint.setColor(mBgColor);
+ canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint);
- for (int k = 0; k <= (graphheight /32) ; k++) {
- float y = (float)(32 * k)+ border;
- mCanvas.drawLine(border, y, graphwidth + border , y, mPaint);
+ mPaint.setColor(mGridColor);
+ for (int row = 0; row <= GRID_LINES; row++) {
+ float y = (graphHeight * row / GRID_LINES) + paddingTop;
+ canvas.drawLine(paddingLeft, y, graphWidth + paddingLeft, y, mPaint);
}
- for (int j = 0; j <= (graphwidth /32); j++) {
- float x = (float)(32 * j)+ border;
- mCanvas.drawLine(x, border, x, graphheight + border, mPaint);
+ for (int col = 0; col <= GRID_LINES; col++) {
+ float x = (graphWidth * col / GRID_LINES) + paddingLeft;
+ canvas.drawLine(x, paddingTop, x, graphHeight + paddingTop, mPaint);
}
- //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++) {
- maxValue = Math.max(maxValue, mData[i]);
- }
- } else {
- maxValue = mData[0];
+ mPaint.setColor(mBarColor);
+ for (int i = 0; i < STATS_SIZE; i++) {
+ float barHeight = mData[i] * graphHeight;
+ float left = (barWidth * i) + paddingLeft;
+ float right = left + barWidth;
+ float bottom = graphHeight + paddingTop;
+ float top = bottom - barHeight;
+ canvas.drawRect(left, top, right, bottom, mPaint);
}
- 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);
+ if (mGraphCameraDevice != null) {
+ mGraphCameraDevice.sendHistogramData();
}
}
}