diff options
author | Doris Liu <tianliu@google.com> | 2013-04-02 17:48:56 -0700 |
---|---|---|
committer | Doris Liu <tianliu@google.com> | 2013-04-03 13:32:48 -0700 |
commit | bbee3bfe85ab29acda2e13c422459d3cb96b1917 (patch) | |
tree | eabb0c5bc398e25ccb1d98afd63bafd131595394 /src/com | |
parent | 5a58fb2146ec75061cc2a9a038628a6b7f340b34 (diff) | |
download | android_packages_apps_Snap-bbee3bfe85ab29acda2e13c422459d3cb96b1917.tar.gz android_packages_apps_Snap-bbee3bfe85ab29acda2e13c422459d3cb96b1917.tar.bz2 android_packages_apps_Snap-bbee3bfe85ab29acda2e13c422459d3cb96b1917.zip |
Improve black bar to keep camera controls in place
Bug: 8340996
Change-Id: Ibca4a9f1ed84bd59e29cc988df346f1567de2a5b
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/camera/CameraActivity.java | 16 | ||||
-rw-r--r-- | src/com/android/camera/PhotoUI.java | 2 | ||||
-rw-r--r-- | src/com/android/camera/ui/CameraControls.java (renamed from src/com/android/camera/ui/SwitcherBackgroundView.java) | 55 | ||||
-rw-r--r-- | src/com/android/camera/ui/CameraRootView.java | 85 | ||||
-rw-r--r-- | src/com/android/camera/ui/RotatableLayout.java | 35 |
5 files changed, 157 insertions, 36 deletions
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java index 3813cce34..1215cecf0 100644 --- a/src/com/android/camera/CameraActivity.java +++ b/src/com/android/camera/CameraActivity.java @@ -118,7 +118,6 @@ public class CameraActivity extends ActivityBase public void init() { boolean landscape = Util.getDisplayRotation(this) % 180 == 90; - setMargins(landscape); mControlsBackground = findViewById(R.id.blocker); mCameraControls = findViewById(R.id.camera_controls); mShutter = (ShutterButton) findViewById(R.id.shutter_button); @@ -318,24 +317,9 @@ public class CameraActivity extends ActivityBase @Override public void onConfigurationChanged(Configuration config) { super.onConfigurationChanged(config); - boolean landscape = (config.orientation == Configuration.ORIENTATION_LANDSCAPE); - setMargins(landscape); mCurrentModule.onConfigurationChanged(config); } - private void setMargins(boolean landscape) { - ViewGroup appRoot = (ViewGroup) findViewById(R.id.content); - FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) appRoot.getLayoutParams(); - int navBarWidth = getResources().getDimensionPixelSize(R.dimen.navigation_bar_width); - int navBarHeight = getResources().getDimensionPixelSize(R.dimen.navigation_bar_height); - if (landscape) { - lp.setMargins(navBarHeight, 0, navBarHeight - navBarWidth, 0); - } else { - lp.setMargins(0, navBarHeight, 0, 0); - } - appRoot.setLayoutParams(lp); - } - @Override public void onPause() { mPaused = true; diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java index 1af870abc..29ebd6a70 100644 --- a/src/com/android/camera/PhotoUI.java +++ b/src/com/android/camera/PhotoUI.java @@ -115,6 +115,8 @@ public class PhotoUI implements PieListener, h = width; } if (mPreviewWidth != w || mPreviewHeight != h) { + mPreviewWidth = w; + mPreviewHeight = h; mController.onScreenSizeChanged(width, height, w, h); } } diff --git a/src/com/android/camera/ui/SwitcherBackgroundView.java b/src/com/android/camera/ui/CameraControls.java index 710412cce..a7d1f215e 100644 --- a/src/com/android/camera/ui/SwitcherBackgroundView.java +++ b/src/com/android/camera/ui/CameraControls.java @@ -27,38 +27,57 @@ import android.widget.FrameLayout.LayoutParams; import com.android.camera.Util; import com.android.gallery3d.R; -/* - * This is a simple view that has a gradient background. The background - * needs to rotate when orientation changes, so that the side of the drawable - * that is dark is always aligned to the side of the screen, and the side that is - * closer to the center of the screen is transparent. - * */ -public class SwitcherBackgroundView extends View +public class CameraControls extends RotatableLayout { - public SwitcherBackgroundView(Context context, AttributeSet attrs) { + private View mBackgroundView; + public CameraControls(Context context, AttributeSet attrs) { super(context, attrs); - setBackgroundResource(R.drawable.switcher_bg); } - public SwitcherBackgroundView(Context context) { + public CameraControls(Context context) { super(context); - setBackgroundResource(R.drawable.switcher_bg); } + @Override public void onConfigurationChanged(Configuration config) { super.onConfigurationChanged(config); + adjustBackground(); + } + + @Override + public void onFinishInflate() { + super.onFinishInflate(); + mBackgroundView = findViewById(R.id.blocker); + } + + // In reverse landscape and reverse portrait, camera controls will be laid out + // on the wrong side of the screen. We need to make adjustment to move the controls + // to the USB side + public void adjustControlsToRightPosition() { + Configuration config = getResources().getConfiguration(); + int orientation = Util.getDisplayRotation((Activity) getContext()); + if (orientation == 270 && config.orientation == Configuration.ORIENTATION_LANDSCAPE) { + flipChildren(); + } + if (orientation == 180 && config.orientation == Configuration.ORIENTATION_PORTRAIT) { + flipChildren(); + } + adjustBackground(); + } + + private void adjustBackground() { // remove current drawable and reset rotation - setBackgroundDrawable(null); - setRotationX(0); - setRotationY(0); + mBackgroundView.setBackgroundDrawable(null); + mBackgroundView.setRotationX(0); + mBackgroundView.setRotationY(0); // if the switcher background is top aligned we need to flip the background // drawable vertically; if left aligned, flip horizontally - int gravity = ((LayoutParams) getLayoutParams()).gravity; + int gravity = ((LayoutParams) mBackgroundView.getLayoutParams()).gravity; if ((gravity & Gravity.TOP) == Gravity.TOP) { - setRotationX(180); + mBackgroundView.setRotationX(180); } else if ((gravity & Gravity.LEFT) == Gravity.LEFT) { - setRotationY(180); + mBackgroundView.setRotationY(180); } - setBackgroundResource(R.drawable.switcher_bg); + mBackgroundView.setBackgroundResource(R.drawable.switcher_bg); } } diff --git a/src/com/android/camera/ui/CameraRootView.java b/src/com/android/camera/ui/CameraRootView.java new file mode 100644 index 000000000..cce649530 --- /dev/null +++ b/src/com/android/camera/ui/CameraRootView.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2013 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.camera.ui; + +import android.app.Activity; +import android.content.Context; +import android.content.res.Configuration; +import android.graphics.Rect; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.RelativeLayout; + +import com.android.camera.Util; +import com.android.gallery3d.R; + +public class CameraRootView extends RelativeLayout + implements RotatableLayout.RotationListener { + + private int mOffset = 0; + public CameraRootView(Context context, AttributeSet attrs) { + super(context, attrs); + // Layout the window as if we did not need navigation bar + setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); + } + + @Override + protected boolean fitSystemWindows(Rect insets) { + super.fitSystemWindows(insets); + // insets include status bar, navigation bar, etc + // In this case, we are only concerned with the size of nav bar + if (mOffset > 0) return true; + FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams(); + if (insets.bottom > 0) { + mOffset = insets.bottom; + } else if (insets.right > 0) { + mOffset = insets.right; + } + Configuration config = getResources().getConfiguration(); + if (config.orientation == Configuration.ORIENTATION_PORTRAIT) { + lp.setMargins(0, 0, 0, mOffset); + } else if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) { + lp.setMargins(0, 0, mOffset, 0); + } + CameraControls controls = (CameraControls) findViewById(R.id.camera_controls); + if (controls != null) { + controls.setRotationListener(this); + controls.adjustControlsToRightPosition(); + } + return true; + } + + @Override + public void onRotation(int rotation) { + FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams(); + int b = lp.bottomMargin; + int t = lp.topMargin; + int l = lp.leftMargin; + int r = lp.rightMargin; + rotation = (rotation + 360) % 360; + if (rotation == 90) { + lp.setMargins(b, l, t, r); + } else if (rotation == 270) { + lp.setMargins(t, r, b, l); + } else if (rotation == 180) { + lp.setMargins(r, b, l, t); + } + } +} diff --git a/src/com/android/camera/ui/RotatableLayout.java b/src/com/android/camera/ui/RotatableLayout.java index 4edec5dd7..6836b39b2 100644 --- a/src/com/android/camera/ui/RotatableLayout.java +++ b/src/com/android/camera/ui/RotatableLayout.java @@ -39,6 +39,10 @@ public class RotatableLayout extends FrameLayout { private static final String TAG = "RotatableLayout"; private int mPrevRotation; + private RotationListener mListener = null; + public interface RotationListener { + public void onRotation(int rotation); + } public RotatableLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @@ -53,12 +57,15 @@ public class RotatableLayout extends FrameLayout { @Override public void onFinishInflate() { // get initial orientation + super.onFinishInflate(); mPrevRotation = Util.getDisplayRotation((Activity) getContext()); } @Override public void onConfigurationChanged(Configuration config) { super.onConfigurationChanged(config); + int rotation = Util.getDisplayRotation((Activity) getContext()); + boolean clockwise = isClockWiseRotation(mPrevRotation, rotation); // Change the size of the layout ViewGroup.LayoutParams lp = getLayoutParams(); int width = lp.width; @@ -66,15 +73,33 @@ public class RotatableLayout extends FrameLayout { lp.height = width; lp.width = height; setLayoutParams(lp); + // rotate all the children - int rotation = Util.getDisplayRotation((Activity) getContext()); - boolean clockwise = isClockWiseRotation(mPrevRotation, rotation); mPrevRotation = rotation; + rotateChildren(clockwise); + } + + protected void rotateChildren(boolean clockwise) { int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); rotate(child, clockwise); } + if (mListener != null) mListener.onRotation(clockwise ? 90 : 270); + } + + protected void flipChildren() { + mPrevRotation = Util.getDisplayRotation((Activity) getContext()); + int childCount = getChildCount(); + for (int i = 0; i < childCount; i++) { + View child = getChildAt(i); + flip(child); + } + if (mListener != null) mListener.onRotation(180); + } + + public void setRotationListener(RotationListener listener) { + mListener = listener; } public static boolean isClockWiseRotation(int prevRotation, int currentRotation) { @@ -181,4 +206,10 @@ public class RotatableLayout extends FrameLayout { lp.height = width; view.setLayoutParams(lp); } + + // Rotate a given view 180 degrees + public static void flip(View view) { + rotateClockwise(view); + rotateClockwise(view); + } }
\ No newline at end of file |