blob: 9e3469f6f8d92ed3bc94c499956a31e4acd254d7 [file] [log] [blame]
Doris Liu048a61c2013-04-02 17:48:56 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.camera.ui;
18
19import android.app.Activity;
20import android.content.Context;
21import android.content.res.Configuration;
22import android.graphics.Rect;
23import android.util.AttributeSet;
24import android.view.Gravity;
25import android.view.View;
26import android.widget.FrameLayout;
27import android.widget.RelativeLayout;
28
29import com.android.camera.Util;
30import com.android.gallery3d.R;
31
32public class CameraRootView extends RelativeLayout
33 implements RotatableLayout.RotationListener {
34
Doris Liu1d8ea532013-04-24 18:09:04 -070035 private int mTopMargin = 0;
36 private int mBottomMargin = 0;
37 private int mLeftMargin = 0;
38 private int mRightMargin = 0;
Doris Liu048a61c2013-04-02 17:48:56 -070039 private int mOffset = 0;
40 public CameraRootView(Context context, AttributeSet attrs) {
41 super(context, attrs);
42 // Layout the window as if we did not need navigation bar
43 setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
44 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
45 }
46
47 @Override
48 protected boolean fitSystemWindows(Rect insets) {
49 super.fitSystemWindows(insets);
50 // insets include status bar, navigation bar, etc
51 // In this case, we are only concerned with the size of nav bar
Doris Liu1d8ea532013-04-24 18:09:04 -070052 if (mOffset > 0) {
53 // Add margin if necessary to the view to ensure nothing is covered
54 // by navigation bar
55 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
56 int right, bottom;
57 if (insets.right > 0) {
58 // navigation bar on the right
59 right = mRightMargin > 0 ? 0 : insets.right;
60 bottom = 0;
61 } else {
62 // navigation bar on the bottom
63 bottom = mBottomMargin > 0 ? 0 : insets.bottom;
64 right = 0;
65 }
66 lp.setMargins(mLeftMargin, mTopMargin, mRightMargin + right, mBottomMargin + bottom);
67 return true;
68 }
Doris Liu048a61c2013-04-02 17:48:56 -070069 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
70 if (insets.bottom > 0) {
71 mOffset = insets.bottom;
72 } else if (insets.right > 0) {
73 mOffset = insets.right;
74 }
75 Configuration config = getResources().getConfiguration();
76 if (config.orientation == Configuration.ORIENTATION_PORTRAIT) {
Doris Liu1d8ea532013-04-24 18:09:04 -070077 mBottomMargin = mOffset;
Doris Liu048a61c2013-04-02 17:48:56 -070078 } else if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Doris Liu1d8ea532013-04-24 18:09:04 -070079 mRightMargin = mOffset;
Doris Liu048a61c2013-04-02 17:48:56 -070080 }
Doris Liu1d8ea532013-04-24 18:09:04 -070081 lp.setMargins( mLeftMargin, mTopMargin, mRightMargin, mBottomMargin);
Doris Liu048a61c2013-04-02 17:48:56 -070082 CameraControls controls = (CameraControls) findViewById(R.id.camera_controls);
83 if (controls != null) {
84 controls.setRotationListener(this);
85 controls.adjustControlsToRightPosition();
86 }
87 return true;
88 }
89
90 @Override
91 public void onRotation(int rotation) {
92 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
Doris Liu1d8ea532013-04-24 18:09:04 -070093 int b = mBottomMargin;
94 int t = mTopMargin;
95 int l = mLeftMargin;
96 int r = mRightMargin;
Doris Liu048a61c2013-04-02 17:48:56 -070097 rotation = (rotation + 360) % 360;
98 if (rotation == 90) {
99 lp.setMargins(b, l, t, r);
100 } else if (rotation == 270) {
101 lp.setMargins(t, r, b, l);
102 } else if (rotation == 180) {
103 lp.setMargins(r, b, l, t);
104 }
Doris Liu1d8ea532013-04-24 18:09:04 -0700105 mLeftMargin = lp.leftMargin;
106 mTopMargin = lp.topMargin;
107 mRightMargin = lp.rightMargin;
108 mBottomMargin = lp.bottomMargin;
Doris Liu048a61c2013-04-02 17:48:56 -0700109 }
110}