Merge "Add support for grid lines overlay." into gb-ub-photos-denali
diff --git a/res/layout/generic_module.xml b/res/layout/generic_module.xml
index 9a2eb64..e7f4961 100644
--- a/res/layout/generic_module.xml
+++ b/res/layout/generic_module.xml
@@ -40,6 +40,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
+ <com.android.camera.ui.GridLines
+ android:id="@+id/grid_lines"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="invisible" />
+
<FrameLayout
android:id="@+id/module_layout"
android:layout_width="match_parent"
diff --git a/res/values/colors.xml b/res/values/colors.xml
index e9dcf50..08ebedb 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -92,4 +92,5 @@
<color name="indicators_background_color">#4c000000</color>
+ <color name="grid_line">#99ffffff</color>
</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index f920317..721b5e5 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -178,4 +178,6 @@
<dimen name="indicator_icon_radius">48dp</dimen>
<dimen name="video_capture_circle_diameter">48dp</dimen>
+
+ <dimen name="grid_line_width">1dp</dimen>
</resources>
diff --git a/src/com/android/camera/app/CameraAppUI.java b/src/com/android/camera/app/CameraAppUI.java
index a1e36e7..2ab2817 100644
--- a/src/com/android/camera/app/CameraAppUI.java
+++ b/src/com/android/camera/app/CameraAppUI.java
@@ -41,6 +41,7 @@
import com.android.camera.settings.SettingsManager;
import com.android.camera.ui.BottomBar;
import com.android.camera.ui.CaptureAnimationOverlay;
+import com.android.camera.ui.GridLines;
import com.android.camera.ui.MainActivityLayout;
import com.android.camera.ui.ModeListView;
import com.android.camera.ui.ModeTransitionView;
@@ -400,6 +401,7 @@
private int mLastRotation;
private int mSwipeState = IDLE;
private PreviewOverlay mPreviewOverlay;
+ private GridLines mGridLines;
private CaptureAnimationOverlay mCaptureOverlay;
private PreviewStatusListener mPreviewStatusListener;
private int mModeCoverState = COVER_HIDDEN;
@@ -832,6 +834,9 @@
mModeOptionsOverlay
= (ModeOptionsOverlay) mCameraRootView.findViewById(R.id.mode_options_overlay);
+ mGridLines = (GridLines) mCameraRootView.findViewById(R.id.grid_lines);
+ mTextureViewHelper.addPreviewAreaSizeChangedListener(mGridLines);
+
mPreviewOverlay = (PreviewOverlay) mCameraRootView.findViewById(R.id.preview_overlay);
mPreviewOverlay.setOnTouchListener(new MyTouchListener());
mPreviewOverlay.setOnPreviewTouchedListener(mModeOptionsOverlay);
@@ -856,6 +861,7 @@
mCameraRootView.removeAllViews();
mModuleUI = null;
mTextureView = null;
+ mGridLines = null;
mPreviewOverlay = null;
mBottomBar = null;
mModeOptionsOverlay = null;
@@ -1041,6 +1047,31 @@
}
}
+ /****************************Grid lines api ******************************/
+
+ /**
+ * Show a set of evenly spaced lines over the preview. The number
+ * of lines horizontally and vertically is determined by
+ * {@link com.android.camera.ui.GridLines}.
+ */
+ public void showGridLines() {
+ if (mGridLines != null) {
+ mGridLines.setVisibility(View.VISIBLE);
+ }
+ }
+
+ /**
+ * Hide the set of evenly spaced grid lines overlaying the preview.
+ */
+ public void hideGridLines() {
+ if (mGridLines != null) {
+ mGridLines.setVisibility(View.INVISIBLE);
+ }
+ }
+
+
+ /****************************Bottom bar api ******************************/
+
/**
* Sets the color of the bottom bar.
*/
diff --git a/src/com/android/camera/ui/GridLines.java b/src/com/android/camera/ui/GridLines.java
new file mode 100644
index 0000000..e93e311
--- /dev/null
+++ b/src/com/android/camera/ui/GridLines.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2014 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.Canvas;
+import android.graphics.Paint;
+import android.graphics.RectF;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.android.camera2.R;
+
+/**
+ * GridLines is a view which directly overlays the preview and draws
+ * evenly spaced grid lines.
+ */
+public class GridLines extends View
+ implements PreviewStatusListener.PreviewAreaSizeChangedListener {
+
+ Paint mPaint = new Paint();
+ float mPreviewWidth = 0f;
+ float mPreviewHeight = 0f;
+
+ public GridLines(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ int strokeWidth = getResources().getDimensionPixelSize(R.dimen.grid_line_width);
+ mPaint.setStrokeWidth(strokeWidth);
+ mPaint.setColor(getResources().getColor(R.color.grid_line));
+ }
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ if (mPreviewWidth > 0 && mPreviewHeight > 0) {
+ float thirdWidth = mPreviewWidth / 3;
+ float thirdHeight = mPreviewHeight / 3;
+ // draw the first vertical line
+ canvas.drawLine(thirdWidth, 0, thirdWidth, mPreviewHeight, mPaint);
+ // draw the second vertical line
+ canvas.drawLine(thirdWidth*2, 0, thirdWidth*2, mPreviewHeight, mPaint);
+
+ // draw the first horizontal line
+ canvas.drawLine(0, thirdHeight, mPreviewWidth, thirdHeight, mPaint);
+ // draw the second horizontal line
+ canvas.drawLine(0, thirdHeight*2, mPreviewWidth, thirdHeight*2, mPaint);
+ }
+ }
+
+ @Override
+ public void onPreviewAreaSizeChanged(RectF previewArea) {
+ mPreviewWidth = previewArea.width();
+ mPreviewHeight = previewArea.height();
+ post(new Runnable() {
+ @Override
+ public void run() {
+ // Causes another layout pass, which will resize this
+ // view and trigger a redraw of the grid lines.
+ matchPreviewDimensions();
+ }
+ });
+ }
+
+ /**
+ * Reset the height and width of this view to match cached the height
+ * and width of the preview.
+ */
+ private void matchPreviewDimensions() {
+ if (mPreviewWidth > 0 && mPreviewHeight > 0) {
+ ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) getLayoutParams();
+ params.width = (int) mPreviewWidth;
+ params.height = (int) mPreviewHeight;
+ setLayoutParams(params);
+ }
+ }
+}
\ No newline at end of file