diff options
| author | Issei Suzuki <issei@google.com> | 2019-07-02 12:31:34 +0200 |
|---|---|---|
| committer | Issei Suzuki <issei@google.com> | 2019-07-02 12:33:13 +0200 |
| commit | f0412592dbaeff8ce2556e1fcb55b9ec1cbdb817 (patch) | |
| tree | 158fbc65cb02f60471e27c3cff5c48e802eba16d /core/java/android/view/SurfaceView.java | |
| parent | 4cb04496df42b310f87dcb5ac672481fba0baccb (diff) | |
Clean up SurfaceView
Bug: 136538998
Test: no-op refactoring CL. Existing unit tests still pass.
Change-Id: Ibd0310a87ed38aa48215be9cba54f1c7a2a8a9fa
Diffstat (limited to 'core/java/android/view/SurfaceView.java')
| -rw-r--r-- | core/java/android/view/SurfaceView.java | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index f661e0646d75..6563e03853fb 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -23,7 +23,6 @@ import static android.view.WindowManagerPolicyConstants.APPLICATION_PANEL_SUBLAY import android.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.res.CompatibilityInfo.Translator; -import android.content.res.Configuration; import android.graphics.BlendMode; import android.graphics.Canvas; import android.graphics.Color; @@ -102,8 +101,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb private static final boolean DEBUG = false; @UnsupportedAppUsage - final ArrayList<SurfaceHolder.Callback> mCallbacks - = new ArrayList<SurfaceHolder.Callback>(); + final ArrayList<SurfaceHolder.Callback> mCallbacks = new ArrayList<>(); final int[] mLocation = new int[2]; @@ -127,7 +125,6 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb SurfaceControl mDeferredDestroySurfaceControl; SurfaceControl mBackgroundControl; final Rect mTmpRect = new Rect(); - final Configuration mConfiguration = new Configuration(); Paint mRoundedViewportPaint; @@ -137,25 +134,16 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb boolean mIsCreating = false; private volatile boolean mRtHandlingPositionUpdates = false; - private final ViewTreeObserver.OnScrollChangedListener mScrollChangedListener - = new ViewTreeObserver.OnScrollChangedListener() { - @Override - public void onScrollChanged() { - updateSurface(); - } - }; + private final ViewTreeObserver.OnScrollChangedListener mScrollChangedListener = + this::updateSurface; @UnsupportedAppUsage - private final ViewTreeObserver.OnPreDrawListener mDrawListener = - new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - // reposition ourselves where the surface is - mHaveFrame = getWidth() > 0 && getHeight() > 0; - updateSurface(); - return true; - } - }; + private final ViewTreeObserver.OnPreDrawListener mDrawListener = () -> { + // reposition ourselves where the surface is + mHaveFrame = getWidth() > 0 && getHeight() > 0; + updateSurface(); + return true; + }; boolean mRequestedVisible = false; boolean mWindowVisibility = false; @@ -190,7 +178,6 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) final Rect mSurfaceFrame = new Rect(); int mLastSurfaceWidth = -1, mLastSurfaceHeight = -1; - private Translator mTranslator; private boolean mGlobalListenersAdded; private boolean mAttachedToWindow; @@ -555,9 +542,9 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb return; } - mTranslator = viewRoot.mTranslator; - if (mTranslator != null) { - mSurface.setCompatibilityTranslator(mTranslator); + final Translator translator = viewRoot.mTranslator; + if (translator != null) { + mSurface.setCompatibilityTranslator(translator); } int myWidth = mRequestedWidth; @@ -596,8 +583,8 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb mScreenRect.top = mWindowSpaceTop; mScreenRect.right = mWindowSpaceLeft + getWidth(); mScreenRect.bottom = mWindowSpaceTop + getHeight(); - if (mTranslator != null) { - mTranslator.translateRectInAppWindowToScreen(mScreenRect); + if (translator != null) { + translator.translateRectInAppWindowToScreen(mScreenRect); } final Rect surfaceInsets = getParentSurfaceInsets(); @@ -683,11 +670,11 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb mSurfaceFrame.left = 0; mSurfaceFrame.top = 0; - if (mTranslator == null) { + if (translator == null) { mSurfaceFrame.right = mSurfaceWidth; mSurfaceFrame.bottom = mSurfaceHeight; } else { - float appInvertedScale = mTranslator.applicationInvertedScale; + float appInvertedScale = translator.applicationInvertedScale; mSurfaceFrame.right = (int) (mSurfaceWidth * appInvertedScale + 0.5f); mSurfaceFrame.bottom = (int) (mSurfaceHeight * appInvertedScale + 0.5f); } @@ -821,8 +808,8 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb mScreenRect.set(mWindowSpaceLeft, mWindowSpaceTop, mWindowSpaceLeft + mLocation[0], mWindowSpaceTop + mLocation[1]); - if (mTranslator != null) { - mTranslator.translateRectInAppWindowToScreen(mScreenRect); + if (translator != null) { + translator.translateRectInAppWindowToScreen(mScreenRect); } if (mSurfaceControl == null) { @@ -1037,7 +1024,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb synchronized (mCallbacks) { // This is a linear search, but in practice we'll // have only a couple callbacks, so it doesn't matter. - if (mCallbacks.contains(callback) == false) { + if (!mCallbacks.contains(callback)) { mCallbacks.add(callback); } } |
