From 5f3cb4a584545927b3dcecb7cb47eb7edb6d2d5d Mon Sep 17 00:00:00 2001 From: Dongwon Kang Date: Wed, 19 Nov 2014 18:12:44 +0900 Subject: [PATCH] TIF: implement gatherTransparentRegion() and dispatchDraw() in TvView. Background: because the hole-punching code lives only in SurfaceView, the overlay view can be covered by the application if the TV input changes the position of SurfaceView via Session.layoutSurface(). This change punches a hole as large as TvView so that the underlying overlayview can be shown properly. Bug: 18420642 Change-Id: If9a829367083ce2002a4c4a4e4a4bbb623f7ad96 --- media/java/android/media/tv/TvView.java | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/media/java/android/media/tv/TvView.java b/media/java/android/media/tv/TvView.java index f9d84c1b037f3..6fc1b82ff2d48 100644 --- a/media/java/android/media/tv/TvView.java +++ b/media/java/android/media/tv/TvView.java @@ -18,7 +18,10 @@ package android.media.tv; import android.annotation.SystemApi; import android.content.Context; +import android.graphics.Canvas; +import android.graphics.PorterDuff; import android.graphics.Rect; +import android.graphics.Region; import android.media.tv.TvInputManager.Session; import android.media.tv.TvInputManager.Session.FinishedInputEventCallback; import android.media.tv.TvInputManager.SessionCallback; @@ -592,6 +595,42 @@ public class TvView extends ViewGroup { childState << MEASURED_HEIGHT_STATE_SHIFT)); } + @Override + public boolean gatherTransparentRegion(Region region) { + if (mWindowZOrder != ZORDER_ON_TOP) { + if (region != null) { + int width = getWidth(); + int height = getHeight(); + if (width > 0 && height > 0) { + int location[] = new int[2]; + getLocationInWindow(location); + int left = location[0]; + int top = location[1]; + region.op(left, top, left + width, top + height, Region.Op.UNION); + } + } + } + return super.gatherTransparentRegion(region); + } + + @Override + public void draw(Canvas canvas) { + if (mWindowZOrder != ZORDER_ON_TOP) { + // Punch a hole so that the underlying overlay view and surface can be shown. + canvas.drawColor(0, PorterDuff.Mode.CLEAR); + } + super.draw(canvas); + } + + @Override + protected void dispatchDraw(Canvas canvas) { + if (mWindowZOrder != ZORDER_ON_TOP) { + // Punch a hole so that the underlying overlay view and surface can be shown. + canvas.drawColor(0, PorterDuff.Mode.CLEAR); + } + super.dispatchDraw(canvas); + } + @Override protected void onVisibilityChanged(View changedView, int visibility) { super.onVisibilityChanged(changedView, visibility);