summaryrefslogtreecommitdiff
path: root/java/com
diff options
context:
space:
mode:
authorroldenburg <roldenburg@google.com>2017-06-20 16:42:44 -0700
committerEric Erfanian <erfanian@google.com>2017-06-21 13:48:40 -0700
commit513e3a3dfa54ecaa2e12a049cd2b5e7dc7b8dc47 (patch)
tree83ddc461371decdbb299a802aa8c1dbda155a13c /java/com
parentd06625785de67bf27ba9ad4ff02dfd20011edb74 (diff)
Don't pass a null Context to RenderScript
We need to check that we have a Context before passing it to RenderScript.create. getContext can return null if the fragment has been removed. I switched this to an early return approach to avoid the deep nesting and added tests. It is safe to ignore the IfThisThenThat PiperOrigin-RevId: 159633511 Change-Id: If2286a545c2e514c328dff22c48a99b9ed232e88
Diffstat (limited to 'java/com')
-rw-r--r--java/com/android/incallui/video/impl/VideoCallFragment.java76
1 files changed, 41 insertions, 35 deletions
diff --git a/java/com/android/incallui/video/impl/VideoCallFragment.java b/java/com/android/incallui/video/impl/VideoCallFragment.java
index 7d3c5c6e4..67c131af9 100644
--- a/java/com/android/incallui/video/impl/VideoCallFragment.java
+++ b/java/com/android/incallui/video/impl/VideoCallFragment.java
@@ -100,8 +100,8 @@ public class VideoCallFragment extends Fragment
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
static final String ARG_CALL_ID = "call_id";
- private static final float BLUR_PREVIEW_RADIUS = 16.0f;
- private static final float BLUR_PREVIEW_SCALE_FACTOR = 1.0f;
+ @VisibleForTesting static final float BLUR_PREVIEW_RADIUS = 16.0f;
+ @VisibleForTesting static final float BLUR_PREVIEW_SCALE_FACTOR = 1.0f;
private static final float BLUR_REMOTE_RADIUS = 25.0f;
private static final float BLUR_REMOTE_SCALE_FACTOR = 0.25f;
private static final float ASPECT_RATIO_MATCH_THRESHOLD = 0.2f;
@@ -1106,52 +1106,58 @@ public class VideoCallFragment extends Fragment
BLUR_REMOTE_SCALE_FACTOR);
}
- private void updateBlurredImageView(
+ @VisibleForTesting
+ void updateBlurredImageView(
TextureView textureView,
ImageView blurredImageView,
boolean isVideoEnabled,
float blurRadius,
float scaleFactor) {
- boolean didBlur = false;
- long startTimeMillis = SystemClock.elapsedRealtime();
- if (!isVideoEnabled) {
- int width = Math.round(textureView.getWidth() * scaleFactor);
- int height = Math.round(textureView.getHeight() * scaleFactor);
- // This call takes less than 10 milliseconds.
- Bitmap bitmap = textureView.getBitmap(width, height);
- if (bitmap != null) {
- // TODO(mdooley): When the view is first displayed after a rotation the bitmap is empty
- // and thus this blur has no effect.
- // This call can take 100 milliseconds.
- blur(getContext(), bitmap, blurRadius);
-
- // TODO(mdooley): Figure out why only have to apply the transform in landscape mode
- if (width > height) {
- bitmap =
- Bitmap.createBitmap(
- bitmap,
- 0,
- 0,
- bitmap.getWidth(),
- bitmap.getHeight(),
- textureView.getTransform(null),
- true);
- }
+ Context context = getContext();
- blurredImageView.setImageBitmap(bitmap);
- blurredImageView.setVisibility(View.VISIBLE);
- didBlur = true;
- }
+ if (isVideoEnabled || context == null) {
+ blurredImageView.setImageBitmap(null);
+ blurredImageView.setVisibility(View.GONE);
+ return;
}
- if (!didBlur) {
+
+ long startTimeMillis = SystemClock.elapsedRealtime();
+ int width = Math.round(textureView.getWidth() * scaleFactor);
+ int height = Math.round(textureView.getHeight() * scaleFactor);
+
+ // This call takes less than 10 milliseconds.
+ Bitmap bitmap = textureView.getBitmap(width, height);
+
+ if (bitmap == null) {
blurredImageView.setImageBitmap(null);
blurredImageView.setVisibility(View.GONE);
+ return;
}
+ // TODO(mdooley): When the view is first displayed after a rotation the bitmap is empty
+ // and thus this blur has no effect.
+ // This call can take 100 milliseconds.
+ blur(getContext(), bitmap, blurRadius);
+
+ // TODO(mdooley): Figure out why only have to apply the transform in landscape mode
+ if (width > height) {
+ bitmap =
+ Bitmap.createBitmap(
+ bitmap,
+ 0,
+ 0,
+ bitmap.getWidth(),
+ bitmap.getHeight(),
+ textureView.getTransform(null),
+ true);
+ }
+
+ blurredImageView.setImageBitmap(bitmap);
+ blurredImageView.setVisibility(View.VISIBLE);
+
LogUtil.i(
"VideoCallFragment.updateBlurredImageView",
- "didBlur: %b, took %d millis",
- didBlur,
+ "took %d millis",
(SystemClock.elapsedRealtime() - startTimeMillis));
}