diff options
Diffstat (limited to 'src/com/android/camera/ui/RotateLayout.java')
-rw-r--r-- | src/com/android/camera/ui/RotateLayout.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/com/android/camera/ui/RotateLayout.java b/src/com/android/camera/ui/RotateLayout.java index e394aba0b..d322b69f9 100644 --- a/src/com/android/camera/ui/RotateLayout.java +++ b/src/com/android/camera/ui/RotateLayout.java @@ -18,6 +18,7 @@ package com.android.camera.ui; import android.content.Context; import android.graphics.Matrix; +import android.graphics.Rect; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; @@ -32,6 +33,11 @@ public class RotateLayout extends ViewGroup implements Rotatable { private int mOrientation; private Matrix mMatrix = new Matrix(); protected View mChild; + private CameraRootView mRootView; + + public interface Child { + void onApplyWindowInsets(Rect insets, int rootWidth, int rootHeight); + } public RotateLayout(Context context, AttributeSet attrs) { super(context, attrs); @@ -42,6 +48,10 @@ public class RotateLayout extends ViewGroup implements Rotatable { setBackgroundResource(android.R.color.transparent); } + public void setRootView(CameraRootView rootView) { + mRootView = rootView; + } + @Override protected void onFinishInflate() { setupChild(getChildAt(0)); @@ -52,14 +62,22 @@ public class RotateLayout extends ViewGroup implements Rotatable { mChild = child; child.setPivotX(0); child.setPivotY(0); + applyInsetsToChild(); } } + @Override public void addView(View child) { super.addView(child); setupChild(child); } + @Override + public void addView(View child, LayoutParams params) { + super.addView(child, params); + setupChild(child); + } + public void removeView(View v) { super.removeView(v); mOrientation = 0; @@ -145,6 +163,7 @@ public class RotateLayout extends ViewGroup implements Rotatable { } } mOrientation = orientation; + applyInsetsToChild(); if (mChild != null) requestLayout(); } @@ -152,4 +171,12 @@ public class RotateLayout extends ViewGroup implements Rotatable { public int getOrientation() { return mOrientation; } + + private void applyInsetsToChild() { + if (mRootView != null && mChild instanceof Child) { + Rect insets = mRootView.getInsetsForOrientation(mOrientation); + final Child child = (Child) mChild; + child.onApplyWindowInsets(insets, mRootView.getWidth(), mRootView.getHeight()); + } + } } |