summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Wang <jaywang@codeaurora.org>2016-03-15 14:15:43 -0700
committerSteve Kondik <steve@cyngn.com>2016-08-21 18:45:51 -0700
commitd92108bb8d8548f0760fb103286751c62497459d (patch)
tree2dbeffb6d70277a8b2d73c9934a44d60c9164210
parentb79e19bd4d19df831c68a08edda2435e1b6c79f7 (diff)
downloadandroid_packages_apps_Snap-d92108bb8d8548f0760fb103286751c62497459d.zip
android_packages_apps_Snap-d92108bb8d8548f0760fb103286751c62497459d.tar.gz
android_packages_apps_Snap-d92108bb8d8548f0760fb103286751c62497459d.tar.bz2
SnapdragonCamera: Add logic to calculate preview surface ratio
new file is copied from the commit : 51c65e100d6221c8e19d1345e40db2e7d1c5a190 src/com/android/camera/ui/AutoFitSurfaceView.java copied from media/Camera2Basic/Application/src/main/java/com/example/android/ camera2basic/AutoFitTextureView.java CRs-Fixed: 989750 Change-Id: I29a6fd2219991bda9aaa64f174a61b0aa5b71e87
-rw-r--r--src/com/android/camera/ui/AutoFitSurfaceView.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/com/android/camera/ui/AutoFitSurfaceView.java b/src/com/android/camera/ui/AutoFitSurfaceView.java
new file mode 100644
index 0000000..f4903e1
--- /dev/null
+++ b/src/com/android/camera/ui/AutoFitSurfaceView.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 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.example.android.camera2basic;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.TextureView;
+
+/**
+ * A {@link TextureView} that can be adjusted to a specified aspect ratio.
+ */
+public class AutoFitTextureView extends TextureView {
+
+ private int mRatioWidth = 0;
+ private int mRatioHeight = 0;
+
+ public AutoFitTextureView(Context context) {
+ this(context, null);
+ }
+
+ public AutoFitTextureView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public AutoFitTextureView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio
+ * calculated from the parameters. Note that the actual sizes of parameters don't matter, that
+ * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result.
+ *
+ * @param width Relative horizontal size
+ * @param height Relative vertical size
+ */
+ public void setAspectRatio(int width, int height) {
+ if (width < 0 || height < 0) {
+ throw new IllegalArgumentException("Size cannot be negative.");
+ }
+ mRatioWidth = width;
+ mRatioHeight = height;
+ requestLayout();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ int width = MeasureSpec.getSize(widthMeasureSpec);
+ int height = MeasureSpec.getSize(heightMeasureSpec);
+ if (0 == mRatioWidth || 0 == mRatioHeight) {
+ setMeasuredDimension(width, height);
+ } else {
+ if (width < height * mRatioWidth / mRatioHeight) {
+ setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
+ } else {
+ setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
+ }
+ }
+ }
+
+}