summaryrefslogtreecommitdiff
path: root/java/com/android/incallui/answer/impl/FixedAspectSurfaceView.java
diff options
context:
space:
mode:
authorEric Erfanian <erfanian@google.com>2017-03-21 10:11:17 -0700
committerEric Erfanian <erfanian@google.com>2017-03-21 10:11:17 -0700
commitfc37b02f5d3381a7882770941e461b13b679b6ef (patch)
tree23ce96100a89f1cf8847a4967efd35e56b6f8092 /java/com/android/incallui/answer/impl/FixedAspectSurfaceView.java
parent30ccc4f3aa6da94f0bb8a01a880a6353b883b263 (diff)
Update AOSP Dialer source from internal google3 repository at
cl/150756069 Test: make, treehugger This CL updates the AOSP Dialer source with all the changes that have gone into the private google3 repository. This includes all the changes from cl/150392808 (3/16/2017) to cl/150756069 (3/21/2017). This goal of these drops is to keep the AOSP source in sync with the internal google3 repository. Currently these sync are done by hand with very minor modifications to the internal source code. See the Android.mk file for list of modifications. Our current goal is to do frequent drops (daily if possible) and eventually switched to an automated process. Change-Id: I0888b5db52efb28eb8194600e0c7804592f975f3
Diffstat (limited to 'java/com/android/incallui/answer/impl/FixedAspectSurfaceView.java')
-rw-r--r--java/com/android/incallui/answer/impl/FixedAspectSurfaceView.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/java/com/android/incallui/answer/impl/FixedAspectSurfaceView.java b/java/com/android/incallui/answer/impl/FixedAspectSurfaceView.java
new file mode 100644
index 000000000..ad7d94d95
--- /dev/null
+++ b/java/com/android/incallui/answer/impl/FixedAspectSurfaceView.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2017 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.incallui.answer.impl;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.view.SurfaceView;
+import android.view.View;
+import com.android.dialer.common.Assert;
+
+/**
+ * A SurfaceView that maintains its aspect ratio to be a desired target value.
+ *
+ * <p>The FixedAspectSurfaceView will not be able to maintain the requested aspect ratio if both the
+ * width and the height are exactly determined by the layout. To avoid this, ensure that either the
+ * height or the width is adjustable by the view; for example, by setting the layout parameters to
+ * be WRAP_CONTENT for the dimension that is best adjusted to maintain the aspect ratio.
+ */
+public class FixedAspectSurfaceView extends SurfaceView {
+
+ /** Desired width/height ratio */
+ private float mAspectRatio;
+
+ private final boolean scaleWidth;
+ private final boolean scaleHeight;
+
+ public FixedAspectSurfaceView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ // Get initial aspect ratio from custom attributes
+ TypedArray a =
+ context.getTheme().obtainStyledAttributes(attrs, R.styleable.FixedAspectSurfaceView, 0, 0);
+ scaleHeight = a.getBoolean(R.styleable.FixedAspectSurfaceView_scaleHeight, false);
+ scaleWidth = a.getBoolean(R.styleable.FixedAspectSurfaceView_scaleWidth, false);
+ Assert.checkArgument(scaleHeight != scaleWidth, "Must either scale width or height");
+ setAspectRatio(a.getFloat(R.styleable.FixedAspectSurfaceView_aspectRatio, 1.f));
+ a.recycle();
+ }
+
+ /**
+ * Set the desired aspect ratio for this view.
+ *
+ * @param aspect the desired width/height ratio in the current UI orientation. Must be a positive
+ * value.
+ */
+ public void setAspectRatio(float aspect) {
+ Assert.checkArgument(aspect >= 0, "Aspect ratio must be positive");
+ mAspectRatio = aspect;
+ requestLayout();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ int width = MeasureSpec.getSize(widthMeasureSpec);
+ int height = MeasureSpec.getSize(heightMeasureSpec);
+
+ // Do the scaling
+ if (scaleWidth) {
+ width = (int) (height * mAspectRatio);
+ } else if (scaleHeight) {
+ height = (int) (width / mAspectRatio);
+ }
+
+ // Override width/height if needed for EXACTLY and AT_MOST specs
+ width = View.resolveSizeAndState(width, widthMeasureSpec, 0);
+ height = View.resolveSizeAndState(height, heightMeasureSpec, 0);
+
+ // Finally set the calculated dimensions
+ setMeasuredDimension(width, height);
+ }
+}