summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2016-11-29 13:34:34 +0100
committerMichael Bestas <mikeioannina@gmail.com>2016-12-23 00:33:27 -0800
commit2bf3a05c66d350e253956503a9388946c1be1c1c (patch)
treecd665058b5a1485d8797087b43515c0bd9f58ef4
parent3acc722b184214a4cd76f7ef77b12658297e1f87 (diff)
downloadandroid_packages_apps_Snap-2bf3a05c66d350e253956503a9388946c1be1c1c.zip
android_packages_apps_Snap-2bf3a05c66d350e253956503a9388946c1be1c1c.tar.gz
android_packages_apps_Snap-2bf3a05c66d350e253956503a9388946c1be1c1c.tar.bz2
Use transparent navigation bar.
Ensures a 16:9 preview isn't scaled on a 16:9 screen just due to the navigation bar being shown. Change-Id: I7ca7778b0405d3e9ac7ae1db3e7a56cacd703e3b
-rw-r--r--res/layout/camera_filmstrip.xml3
-rw-r--r--res/layout/filmstrip_bottom_controls.xml1
-rw-r--r--res/layout/list_menu_item.xml50
-rw-r--r--res/values/styles.xml1
-rw-r--r--src/com/android/camera/BaseUI.java5
-rw-r--r--src/com/android/camera/CameraActivity.java52
-rw-r--r--src/com/android/camera/PhotoMenu.java51
-rw-r--r--src/com/android/camera/PhotoUI.java52
-rw-r--r--src/com/android/camera/VideoMenu.java25
-rw-r--r--src/com/android/camera/VideoUI.java42
-rw-r--r--src/com/android/camera/ui/CameraControls.java17
-rw-r--r--src/com/android/camera/ui/CameraRootView.java143
-rw-r--r--src/com/android/camera/ui/ListMenu.java53
-rw-r--r--src/com/android/camera/ui/ListMenuItem.java4
-rw-r--r--src/com/android/camera/ui/ListSubMenu.java38
-rw-r--r--src/com/android/camera/ui/RenderOverlay.java26
-rw-r--r--src/com/android/camera/ui/RotateLayout.java27
17 files changed, 336 insertions, 254 deletions
diff --git a/res/layout/camera_filmstrip.xml b/res/layout/camera_filmstrip.xml
index cb49367..30da433 100644
--- a/res/layout/camera_filmstrip.xml
+++ b/res/layout/camera_filmstrip.xml
@@ -23,7 +23,8 @@
<com.android.camera.ui.FilmStripView
android:id="@+id/filmstrip_view"
android:layout_width="match_parent"
- android:layout_height="match_parent" />
+ android:layout_height="match_parent"
+ android:clipToPadding="false" />
<!--com.android.camera.ui.FitSystemUiFrameLayout-->
<FrameLayout
diff --git a/res/layout/filmstrip_bottom_controls.xml b/res/layout/filmstrip_bottom_controls.xml
index ef370a3..2d6db81 100644
--- a/res/layout/filmstrip_bottom_controls.xml
+++ b/res/layout/filmstrip_bottom_controls.xml
@@ -22,6 +22,7 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:padding="10dp"
+ android:fitsSystemWindows="true"
android:visibility="visible" >
<ImageButton
diff --git a/res/layout/list_menu_item.xml b/res/layout/list_menu_item.xml
index 45ab11f..36e41d2 100644
--- a/res/layout/list_menu_item.xml
+++ b/res/layout/list_menu_item.xml
@@ -28,37 +28,41 @@
-->
<com.android.camera.ui.ListMenuItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
- android:layout_height="wrap_content"
+ android:layout_height="@dimen/setting_row_height"
android:background="@drawable/setting_list_item_bg"
- android:padding="5dip" >
+ android:orientation="horizontal"
+ android:gravity="center_vertical"
+ android:paddingLeft="8dip"
+ android:paddingRight="8dip" >
<ImageView
android:id="@+id/list_image"
android:layout_width="@dimen/setting_item_icon_width"
android:layout_height="@dimen/setting_item_icon_width"
- android:layout_alignParentStart="true"
- android:layout_marginEnd="15dp"
- android:layout_centerVertical="true"
- android:gravity="center" />
+ android:layout_marginRight="16dp" />
- <TextView
- android:id="@+id/title"
- android:layout_width="wrap_content"
+ <LinearLayout
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_toEndOf="@+id/list_image"
- android:textColor="@android:color/white"
- android:textStyle="bold" />
+ android:orientation="vertical">
- <TextView
- android:id="@+id/current_setting"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/title"
- android:layout_marginTop="1dip"
- android:layout_toEndOf="@+id/list_image"
- android:text="@string/crop_save"
- android:textColor="@color/white"
- android:textSize="10dip"
- android:textStyle="bold" />
+ <TextView
+ android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textColor="@android:color/white"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/current_setting"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="1dip"
+ android:text="@string/crop_save"
+ android:textColor="@color/white"
+ android:textSize="10dip"
+ android:textStyle="bold" />
+
+ </LinearLayout>
</com.android.camera.ui.ListMenuItem>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 3e3ef16..50a279a 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -25,6 +25,7 @@
<item name="android:windowTitleSize">0dp</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@android:color/black</item>
+ <item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:colorBackground">@android:color/black</item>
<item name="android:colorBackgroundCacheHint">@android:color/black</item>
<item name="android:actionBarStyle">@style/Material.ActionBar</item>
diff --git a/src/com/android/camera/BaseUI.java b/src/com/android/camera/BaseUI.java
index 4dad158..40b97e4 100644
--- a/src/com/android/camera/BaseUI.java
+++ b/src/com/android/camera/BaseUI.java
@@ -24,6 +24,7 @@ import android.view.View;
import android.view.ViewGroup;
import com.android.camera.ui.CameraControls;
+import com.android.camera.ui.CameraRootView;
import com.android.camera.ui.CaptureAnimationOverlay;
import com.android.camera.ui.ModuleSwitcher;
import com.android.camera.ui.RecordingTime;
@@ -46,7 +47,7 @@ public abstract class BaseUI {
protected final View mPreviewCover;
protected final CameraActivity mActivity;
- protected final ViewGroup mRootView;
+ protected final CameraRootView mRootView;
protected final CameraControls mCameraControls;
protected final RecordingTime mRecordingTime;
@@ -63,7 +64,7 @@ public abstract class BaseUI {
public BaseUI(CameraActivity activity, ViewGroup rootView, int layout) {
mActivity = activity;
- mRootView = rootView;
+ mRootView = (CameraRootView) rootView;
mActivity.getLayoutInflater().inflate(layout, mRootView, true);
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index ac3f2bc..d6224cd 100644
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -102,6 +102,7 @@ import com.android.camera.data.MediaDetails;
import com.android.camera.data.SimpleViewData;
import com.android.camera.exif.ExifInterface;
import com.android.camera.tinyplanet.TinyPlanetFragment;
+import com.android.camera.ui.CameraRootView;
import com.android.camera.ui.DetailsDialog;
import com.android.camera.ui.FilmStripView;
import com.android.camera.ui.FilmStripView.ImageData;
@@ -203,10 +204,10 @@ public class CameraActivity extends Activity
private CaptureModule mCaptureModule;
private FrameLayout mAboveFilmstripControlLayout;
private FrameLayout mCameraRootFrame;
- private View mCameraPhotoModuleRootView;
- private View mCameraVideoModuleRootView;
- private View mCameraPanoModuleRootView;
- private View mCameraCaptureModuleRootView;
+ private CameraRootView mCameraPhotoModuleRootView;
+ private CameraRootView mCameraVideoModuleRootView;
+ private CameraRootView mCameraPanoModuleRootView;
+ private CameraRootView mCameraCaptureModuleRootView;
private FilmStripView mFilmStripView;
private ProgressBar mBottomProgress;
private View mPanoStitchingPanel;
@@ -245,7 +246,8 @@ public class CameraActivity extends Activity
private LocalMediaObserver mLocalVideosObserver;
private SettingsManager mSettingsManager;
- private final int DEFAULT_SYSTEM_UI_VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
+ private final int DEFAULT_SYSTEM_UI_VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
private boolean mPendingDeletion = false;
@@ -638,14 +640,10 @@ public class CameraActivity extends Activity
View decorView = getWindow().getDecorView();
int currentSystemUIVisibility = decorView.getSystemUiVisibility();
- boolean hidePreview = SystemProperties.getBoolean("camera.ui.no_navigation_bar", false);
int systemUIVisibility = DEFAULT_SYSTEM_UI_VISIBILITY;
- int systemUINotVisible = View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN;
- if (hidePreview) {
- systemUIVisibility |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
- systemUINotVisible |= (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
- }
+ int systemUINotVisible = View.SYSTEM_UI_FLAG_LOW_PROFILE
+ | View.SYSTEM_UI_FLAG_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
int newSystemUIVisibility = systemUIVisibility
| (visible ? View.SYSTEM_UI_FLAG_VISIBLE : systemUINotVisible);
@@ -1465,10 +1463,14 @@ public class CameraActivity extends Activity
LayoutInflater inflater = getLayoutInflater();
View rootLayout = inflater.inflate(R.layout.camera, null, false);
mCameraRootFrame = (FrameLayout)rootLayout.findViewById(R.id.camera_root_frame);
- mCameraPhotoModuleRootView = rootLayout.findViewById(R.id.camera_photo_root);
- mCameraVideoModuleRootView = rootLayout.findViewById(R.id.camera_video_root);
- mCameraPanoModuleRootView = rootLayout.findViewById(R.id.camera_pano_root);
- mCameraCaptureModuleRootView = rootLayout.findViewById(R.id.camera_capture_root);
+ mCameraPhotoModuleRootView =
+ (CameraRootView) rootLayout.findViewById(R.id.camera_photo_root);
+ mCameraVideoModuleRootView =
+ (CameraRootView) rootLayout.findViewById(R.id.camera_video_root);
+ mCameraPanoModuleRootView =
+ (CameraRootView) rootLayout.findViewById(R.id.camera_pano_root);
+ mCameraCaptureModuleRootView =
+ (CameraRootView) rootLayout.findViewById(R.id.camera_capture_root);
calculateDisplayWidth();
@@ -2130,20 +2132,18 @@ public class CameraActivity extends Activity
selectModule(moduleIndex);
}
- private View getModuleRootView(int moduleIndex) {
- final View v;
+ private CameraRootView getModuleRootView(int moduleIndex) {
if (mCurrentModuleIndex == ModuleSwitcher.PHOTO_MODULE_INDEX) {
- v = mCameraPhotoModuleRootView;
+ return mCameraPhotoModuleRootView;
} else if (mCurrentModuleIndex == ModuleSwitcher.VIDEO_MODULE_INDEX) {
- v = mCameraVideoModuleRootView;
+ return mCameraVideoModuleRootView;
} else if (mCurrentModuleIndex == ModuleSwitcher.WIDE_ANGLE_PANO_MODULE_INDEX) {
- v = mCameraPanoModuleRootView;
+ return mCameraPanoModuleRootView;
} else if (mCurrentModuleIndex == ModuleSwitcher.CAPTURE_MODULE_INDEX) {
- v = mCameraCaptureModuleRootView;
+ return mCameraCaptureModuleRootView;
} else {
- v = mCameraPhotoModuleRootView;
+ return mCameraPhotoModuleRootView;
}
- return v;
}
private View selectModule(int moduleIndex) {
@@ -2242,6 +2242,10 @@ public class CameraActivity extends Activity
}
private void openModule(CameraModule module) {
+ // Re-apply the last fitSystemWindows() run. Our views rely on this, but
+ // the framework's ActionBarOverlayLayout effectively prevents this if the
+ // actual insets haven't changed.
+ getModuleRootView(mCurrentModuleIndex).redoFitSystemWindows();
module.onResumeBeforeSuper();
module.onResumeAfterSuper();
}
diff --git a/src/com/android/camera/PhotoMenu.java b/src/com/android/camera/PhotoMenu.java
index 04346eb..8a91df2 100644
--- a/src/com/android/camera/PhotoMenu.java
+++ b/src/com/android/camera/PhotoMenu.java
@@ -52,6 +52,7 @@ import android.widget.FrameLayout.LayoutParams;
import com.android.camera.CameraPreference.OnPreferenceChangedListener;
import com.android.camera.TsMakeupManager.MakeupLevelListener;
import com.android.camera.app.CameraApp;
+import com.android.camera.ui.CameraRootView;
import com.android.camera.ui.CountdownTimerPopup;
import com.android.camera.ui.ListSubMenu;
import com.android.camera.ui.ListMenu;
@@ -62,8 +63,6 @@ import com.android.camera.ui.RotateTextToast;
import org.codeaurora.snapcam.R;
import android.widget.HorizontalScrollView;
import android.view.ViewGroup;
-import android.view.WindowManager;
-import android.view.Display;
import com.android.camera.util.CameraUtil;
import java.util.Locale;
@@ -995,8 +994,6 @@ public class PhotoMenu extends MenuController
if (!mIsDefaultToPortrait) {
rotation = (rotation + 90) % 360;
}
- WindowManager wm = (WindowManager) mActivity.getSystemService(Context.WINDOW_SERVICE);
- Display display = wm.getDefaultDisplay();
CharSequence[] entries = pref.getEntries();
CharSequence[] entryValues = pref.getEntryValues();
@@ -1025,26 +1022,26 @@ public class PhotoMenu extends MenuController
LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
- FrameLayout basic = (FrameLayout) inflater.inflate(
- gridRes, null, false);
+ FrameLayout basic = (FrameLayout) inflater.inflate(gridRes, null, false);
mUI.dismissSceneModeMenu();
- LinearLayout previewMenuLayout = new LinearLayout(mActivity);
- mUI.setPreviewMenuLayout(previewMenuLayout);
+ mUI.setPreviewMenuLayout(basic);
ViewGroup.LayoutParams params = null;
+ CameraRootView rootView = mUI.getRootView();
if (portrait) {
params = new ViewGroup.LayoutParams(size, LayoutParams.MATCH_PARENT);
- previewMenuLayout.setLayoutParams(params);
- ((ViewGroup) mUI.getRootView()).addView(previewMenuLayout);
} else {
params = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, size);
- previewMenuLayout.setLayoutParams(params);
- ((ViewGroup) mUI.getRootView()).addView(previewMenuLayout);
- previewMenuLayout.setY(display.getHeight() - size);
+
+ int rootViewBottom = rootView.getClientRectForOrientation(rotation).bottom;
+ basic.setY(rootViewBottom - size);
}
- basic.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
- LayoutParams.MATCH_PARENT));
+ basic.setLayoutParams(params);
+ rootView.addView(basic);
+
LinearLayout layout = (LinearLayout) basic.findViewById(R.id.layout);
+ Rect insets = rootView.getInsetsForOrientation(rotation);
+ layout.setPadding(insets.left, insets.top, insets.right, insets.bottom);
final View[] views = new View[entries.length];
int init = pref.getCurrentIndex();
@@ -1099,7 +1096,6 @@ public class PhotoMenu extends MenuController
layout2.setVisibility(View.GONE);
}
}
- previewMenuLayout.addView(basic);
mPreviewMenu = basic;
}
@@ -1146,8 +1142,6 @@ public class PhotoMenu extends MenuController
if (!mIsDefaultToPortrait) {
rotation = (rotation + 90) % 360;
}
- WindowManager wm = (WindowManager) mActivity.getSystemService(Context.WINDOW_SERVICE);
- Display display = wm.getDefaultDisplay();
CharSequence[] entries = pref.getEntries();
Resources r = mActivity.getResources();
@@ -1178,22 +1172,24 @@ public class PhotoMenu extends MenuController
gridRes, null, false);
mUI.dismissSceneModeMenu();
- LinearLayout previewMenuLayout = new LinearLayout(mActivity);
- mUI.setPreviewMenuLayout(previewMenuLayout);
+ mUI.setPreviewMenuLayout(basic);
ViewGroup.LayoutParams params = null;
+ CameraRootView rootView = mUI.getRootView();
if (portrait) {
params = new ViewGroup.LayoutParams(size, LayoutParams.MATCH_PARENT);
- previewMenuLayout.setLayoutParams(params);
- ((ViewGroup) mUI.getRootView()).addView(previewMenuLayout);
} else {
params = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, size);
- previewMenuLayout.setLayoutParams(params);
- ((ViewGroup) mUI.getRootView()).addView(previewMenuLayout);
- previewMenuLayout.setY(display.getHeight() - size);
+
+ int rootViewBottom = rootView.getClientRectForOrientation(rotation).bottom;
+ basic.setY(rootViewBottom - size);
}
- basic.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
- LayoutParams.MATCH_PARENT));
+ basic.setLayoutParams(params);
+ rootView.addView(basic);
+
LinearLayout layout = (LinearLayout) basic.findViewById(R.id.layout);
+ Rect insets = rootView.getInsetsForOrientation(rotation);
+ layout.setPadding(insets.left, insets.top, insets.right, insets.bottom);
+
final View[] views = new View[entries.length];
int init = pref.getCurrentIndex();
for (int i = 0; i < entries.length; i++) {
@@ -1230,7 +1226,6 @@ public class PhotoMenu extends MenuController
label.setText(entries[i]);
layout.addView(layout2);
}
- previewMenuLayout.addView(basic);
mPreviewMenu = basic;
}
diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java
index b81578f..85bd167 100644
--- a/src/com/android/camera/PhotoUI.java
+++ b/src/com/android/camera/PhotoUI.java
@@ -131,7 +131,7 @@ public class PhotoUI extends BaseUI implements PieListener,
private boolean mPrevOrientationResize;
private RotateLayout mMenuLayout;
private RotateLayout mSubMenuLayout;
- private LinearLayout mPreviewMenuLayout;
+ private ViewGroup mPreviewMenuLayout;
private LinearLayout mMakeupMenuLayout;
private int mPreviewOrientation = -1;
@@ -440,7 +440,7 @@ public class PhotoUI extends BaseUI implements PieListener,
mController.onPreviewUIDestroyed();
}
- public View getRootView() {
+ public CameraRootView getRootView() {
return mRootView;
}
@@ -690,7 +690,7 @@ public class PhotoUI extends BaseUI implements PieListener,
return mMenuLayout;
}
- public void setPreviewMenuLayout(LinearLayout layout) {
+ public void setPreviewMenuLayout(ViewGroup layout) {
mPreviewMenuLayout = layout;
}
@@ -710,6 +710,7 @@ public class PhotoUI extends BaseUI implements PieListener,
if (level == 1) {
if (mMenuLayout == null) {
mMenuLayout = new RotateLayout(mActivity, null);
+ mMenuLayout.setRootView(mRootView);
if (mRootView.getLayoutDirection() != View.LAYOUT_DIRECTION_RTL) {
params = new FrameLayout.LayoutParams(
CameraActivity.SETTING_LIST_WIDTH_1, LayoutParams.WRAP_CONTENT,
@@ -720,15 +721,17 @@ public class PhotoUI extends BaseUI implements PieListener,
Gravity.RIGHT | Gravity.TOP);
}
mMenuLayout.setLayoutParams(params);
- ((ViewGroup) mRootView).addView(mMenuLayout);
+ mRootView.addView(mMenuLayout);
}
+ mMenuLayout.addView(popup, new RotateLayout.LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mMenuLayout.setOrientation(mOrientation, true);
- mMenuLayout.addView(popup);
}
if (level == 2) {
if (mSubMenuLayout == null) {
mSubMenuLayout = new RotateLayout(mActivity, null);
- ((ViewGroup) mRootView).addView(mSubMenuLayout);
+ mSubMenuLayout.setRootView(mRootView);
+ mRootView.addView(mSubMenuLayout);
}
if (mRootView.getLayoutDirection() != View.LAYOUT_DIRECTION_RTL) {
params = new FrameLayout.LayoutParams(
@@ -739,13 +742,13 @@ public class PhotoUI extends BaseUI implements PieListener,
CameraActivity.SETTING_LIST_WIDTH_2, LayoutParams.WRAP_CONTENT,
Gravity.RIGHT | Gravity.TOP);
}
- int screenHeight = (mOrientation == 0 || mOrientation == 180)
- ? mRootView.getHeight() : mRootView.getWidth();
+ int containerHeight = mRootView.getClientRectForOrientation(mOrientation).height();
int height = ((ListSubMenu) popup).getPreCalculatedHeight();
- int yBase = ((ListSubMenu) popup).getYBase();
- int y = Math.max(0, yBase);
- if (yBase + height > screenHeight)
- y = Math.max(0, screenHeight - height);
+ int yBase = ((ListSubMenu) popup).getYBase(), y = yBase;
+ if (yBase + height > containerHeight) {
+ y = Math.max(0, containerHeight - height);
+ }
+
if (mRootView.getLayoutDirection() != View.LAYOUT_DIRECTION_RTL) {
params.setMargins(CameraActivity.SETTING_LIST_WIDTH_1, y, 0, 0);
} else {
@@ -754,8 +757,8 @@ public class PhotoUI extends BaseUI implements PieListener,
mSubMenuLayout.setLayoutParams(params);
- mSubMenuLayout.addView(popup);
mSubMenuLayout.setOrientation(mOrientation, true);
+ mSubMenuLayout.addView(popup);
}
if (animate) {
if (level == 1)
@@ -822,14 +825,14 @@ public class PhotoUI extends BaseUI implements PieListener,
public void dismissLevel1() {
if (mMenuLayout != null) {
- ((ViewGroup) mRootView).removeView(mMenuLayout);
+ mRootView.removeView(mMenuLayout);
mMenuLayout = null;
}
}
public void dismissLevel2() {
if (mSubMenuLayout != null) {
- ((ViewGroup) mRootView).removeView(mSubMenuLayout);
+ mRootView.removeView(mSubMenuLayout);
mSubMenuLayout = null;
}
}
@@ -851,14 +854,14 @@ public class PhotoUI extends BaseUI implements PieListener,
public void dismissSceneModeMenu() {
if (mPreviewMenuLayout != null) {
- ((ViewGroup) mRootView).removeView(mPreviewMenuLayout);
+ mRootView.removeView(mPreviewMenuLayout);
mPreviewMenuLayout = null;
}
}
public void removeSceneModeMenu() {
if (mPreviewMenuLayout != null) {
- ((ViewGroup) mRootView).removeView(mPreviewMenuLayout);
+ mRootView.removeView(mPreviewMenuLayout);
mPreviewMenuLayout = null;
}
cleanupListview();
@@ -1010,9 +1013,8 @@ public class PhotoUI extends BaseUI implements PieListener,
// Countdown timer
private void initializeCountDown() {
- mActivity.getLayoutInflater().inflate(R.layout.count_down_to_capture,
- (ViewGroup) mRootView, true);
- mCountDownView = (CountDownView) (mRootView.findViewById(R.id.count_down_to_capture));
+ mActivity.getLayoutInflater().inflate(R.layout.count_down_to_capture, mRootView, true);
+ mCountDownView = (CountDownView) mRootView.findViewById(R.id.count_down_to_capture);
mCountDownView.setCountDownFinishedListener((OnCountDownFinishedListener) mController);
mCountDownView.bringToFront();
mCountDownView.setOrientation(mOrientation);
@@ -1036,7 +1038,7 @@ public class PhotoUI extends BaseUI implements PieListener,
public void startSelfieFlash() {
if(mSelfieView == null)
- mSelfieView = (SelfieFlashView) (mRootView.findViewById(R.id.selfie_flash));
+ mSelfieView = (SelfieFlashView) mRootView.findViewById(R.id.selfie_flash);
mSelfieView.bringToFront();
mSelfieView.open();
mScreenBrightness = setScreenBrightness(1F);
@@ -1044,7 +1046,7 @@ public class PhotoUI extends BaseUI implements PieListener,
public void stopSelfieFlash() {
if(mSelfieView == null)
- mSelfieView = (SelfieFlashView) (mRootView.findViewById(R.id.selfie_flash));
+ mSelfieView = (SelfieFlashView) mRootView.findViewById(R.id.selfie_flash);
mSelfieView.close();
if(mScreenBrightness != 0.0f)
setScreenBrightness(mScreenBrightness);
@@ -1082,11 +1084,11 @@ public class PhotoUI extends BaseUI implements PieListener,
}
public void initDisplayChangeListener() {
- ((CameraRootView) mRootView).setDisplayChangeListener(this);
+ mRootView.setDisplayChangeListener(this);
}
public void removeDisplayChangeListener() {
- ((CameraRootView) mRootView).removeDisplayChangeListener();
+ mRootView.removeDisplayChangeListener();
}
public void pauseFaceDetection() {
@@ -1155,8 +1157,6 @@ public class PhotoUI extends BaseUI implements PieListener,
mSubMenuLayout.setOrientation(orientation, animation);
if (mPreviewMenuLayout != null) {
ViewGroup vg = (ViewGroup) mPreviewMenuLayout.getChildAt(0);
- if (vg != null)
- vg = (ViewGroup) vg.getChildAt(0);
if (vg != null) {
for (int i = vg.getChildCount() - 1; i >= 0; --i) {
RotateLayout l = (RotateLayout) vg.getChildAt(i);
diff --git a/src/com/android/camera/VideoMenu.java b/src/com/android/camera/VideoMenu.java
index cd0f851..a510a51 100644
--- a/src/com/android/camera/VideoMenu.java
+++ b/src/com/android/camera/VideoMenu.java
@@ -25,14 +25,12 @@ import android.content.SharedPreferences;
import android.graphics.Rect;
import android.preference.PreferenceManager;
import android.text.TextUtils;
-import android.view.Display;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
-import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
@@ -41,6 +39,7 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
+import com.android.camera.ui.CameraRootView;
import com.android.camera.ui.ListMenu;
import com.android.camera.ui.ListSubMenu;
import com.android.camera.ui.RotateLayout;
@@ -552,8 +551,6 @@ public class VideoMenu extends MenuController
if (!mIsDefaultToPortrait) {
rotation = (rotation + 90) % 360;
}
- WindowManager wm = (WindowManager) mActivity.getSystemService(Context.WINDOW_SERVICE);
- Display display = wm.getDefaultDisplay();
CharSequence[] entries = pref.getEntries();
Resources r = mActivity.getResources();
@@ -585,22 +582,23 @@ public class VideoMenu extends MenuController
gridRes, null, false);
mUI.dismissSceneModeMenu();
- LinearLayout previewMenuLayout = new LinearLayout(mActivity);
- mUI.setPreviewMenuLayout(previewMenuLayout);
+ mUI.setPreviewMenuLayout(basic);
ViewGroup.LayoutParams params = null;
+ CameraRootView rootView = mUI.getRootView();
if (portrait) {
params = new ViewGroup.LayoutParams(size, LayoutParams.MATCH_PARENT);
- previewMenuLayout.setLayoutParams(params);
- ((ViewGroup) mUI.getRootView()).addView(previewMenuLayout);
} else {
params = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, size);
- previewMenuLayout.setLayoutParams(params);
- ((ViewGroup) mUI.getRootView()).addView(previewMenuLayout);
- previewMenuLayout.setY(display.getHeight() - size);
+
+ int rootViewBottom = rootView.getClientRectForOrientation(rotation).bottom;
+ basic.setY(rootViewBottom - size);
}
- basic.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
- LayoutParams.MATCH_PARENT));
+ basic.setLayoutParams(params);
+ rootView.addView(basic);
+
LinearLayout layout = (LinearLayout) basic.findViewById(R.id.layout);
+ Rect insets = rootView.getInsetsForOrientation(rotation);
+ layout.setPadding(insets.left, insets.top, insets.right, insets.bottom);
final View[] views = new View[entries.length];
int init = pref.getCurrentIndex();
@@ -640,7 +638,6 @@ public class VideoMenu extends MenuController
label.setText(entries[i]);
layout.addView(layout2);
}
- previewMenuLayout.addView(basic);
mPreviewMenu = basic;
}
diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java
index 89d3288..bbec12c 100644
--- a/src/com/android/camera/VideoUI.java
+++ b/src/com/android/camera/VideoUI.java
@@ -94,7 +94,7 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
private boolean mPrevOrientationResize;
private RotateLayout mMenuLayout;
private RotateLayout mSubMenuLayout;
- private LinearLayout mPreviewMenuLayout;
+ private ViewGroup mPreviewMenuLayout;
private SurfaceView mSurfaceView = null;
private int mMaxPreviewWidth = 0;
@@ -457,7 +457,7 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
}
public void initDisplayChangeListener() {
- ((CameraRootView) mRootView).setDisplayChangeListener(this);
+ mRootView.setDisplayChangeListener(this);
}
public void setDisplayOrientation(int orientation) {
@@ -474,7 +474,7 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
}
public void removeDisplayChangeListener() {
- ((CameraRootView) mRootView).removeDisplayChangeListener();
+ mRootView.removeDisplayChangeListener();
}
// no customvideo?
@@ -616,14 +616,14 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
public void dismissLevel1() {
if (mMenuLayout != null) {
- ((ViewGroup) mRootView).removeView(mMenuLayout);
+ mRootView.removeView(mMenuLayout);
mMenuLayout = null;
}
}
public void dismissLevel2() {
if (mSubMenuLayout != null) {
- ((ViewGroup) mRootView).removeView(mSubMenuLayout);
+ mRootView.removeView(mSubMenuLayout);
mSubMenuLayout = null;
}
}
@@ -642,14 +642,14 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
public void dismissSceneModeMenu() {
if (mPreviewMenuLayout != null) {
- ((ViewGroup) mRootView).removeView(mPreviewMenuLayout);
+ mRootView.removeView(mPreviewMenuLayout);
mPreviewMenuLayout = null;
}
}
public void removeSceneModeMenu() {
if (mPreviewMenuLayout != null) {
- ((ViewGroup) mRootView).removeView(mPreviewMenuLayout);
+ mRootView.removeView(mPreviewMenuLayout);
mPreviewMenuLayout = null;
}
cleanupListview();
@@ -670,6 +670,7 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
if (level == 1) {
if (mMenuLayout == null) {
mMenuLayout = new RotateLayout(mActivity, null);
+ mMenuLayout.setRootView(mRootView);
if (mRootView.getLayoutDirection() != View.LAYOUT_DIRECTION_RTL) {
layoutParams = new FrameLayout.LayoutParams(
CameraActivity.SETTING_LIST_WIDTH_1, LayoutParams.WRAP_CONTENT,
@@ -680,19 +681,21 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
Gravity.RIGHT | Gravity.TOP);
}
mMenuLayout.setLayoutParams(layoutParams);
- ((ViewGroup) mRootView).addView(mMenuLayout);
+ mRootView.addView(mMenuLayout);
}
+ mMenuLayout.addView(popup, new RotateLayout.LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mMenuLayout.setOrientation(mOrientation, true);
- mMenuLayout.addView(popup);
}
if (level == 2) {
if (mSubMenuLayout == null) {
mSubMenuLayout = new RotateLayout(mActivity, null);
+ mSubMenuLayout.setRootView(mRootView);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
CameraActivity.SETTING_LIST_WIDTH_2, LayoutParams.WRAP_CONTENT);
mSubMenuLayout.setLayoutParams(params);
- ((ViewGroup) mRootView).addView(mSubMenuLayout);
+ mRootView.addView(mSubMenuLayout);
}
if (mRootView.getLayoutDirection() != View.LAYOUT_DIRECTION_RTL) {
layoutParams = new FrameLayout.LayoutParams(
@@ -704,13 +707,14 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
Gravity.RIGHT | Gravity.TOP);
}
- int screenHeight = (mOrientation == 0 || mOrientation == 180)
- ? mRootView.getHeight() : mRootView.getWidth();
+ final int containerHeight =
+ mRootView.getClientRectForOrientation(mOrientation).height();
int height = ((ListSubMenu) popup).getPreCalculatedHeight();
- int yBase = ((ListSubMenu) popup).getYBase();
- int y = Math.max(0, yBase);
- if (yBase + height > screenHeight)
- y = Math.max(0, screenHeight - height);
+ int yBase = ((ListSubMenu) popup).getYBase(), y = yBase;
+ if (yBase + height > containerHeight) {
+ y = Math.max(0, containerHeight - height);
+ }
+
if (mRootView.getLayoutDirection() != View.LAYOUT_DIRECTION_RTL) {
layoutParams.setMargins(CameraActivity.SETTING_LIST_WIDTH_1, y, 0, 0);
} else {
@@ -735,7 +739,7 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
return mMenuLayout;
}
- public void setPreviewMenuLayout(LinearLayout layout) {
+ public void setPreviewMenuLayout(ViewGroup layout) {
mPreviewMenuLayout = layout;
}
@@ -966,7 +970,7 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
mController.onPreviewUIDestroyed();
}
- public View getRootView() {
+ public CameraRootView getRootView() {
return mRootView;
}
@@ -996,8 +1000,6 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
if (mPreviewMenuLayout != null) {
ViewGroup vg = (ViewGroup) mPreviewMenuLayout.getChildAt(0);
- if (vg != null)
- vg = (ViewGroup) vg.getChildAt(0);
if (vg != null) {
for (int i = vg.getChildCount() - 1; i >= 0; --i) {
RotateLayout l = (RotateLayout) vg.getChildAt(i);
diff --git a/src/com/android/camera/ui/CameraControls.java b/src/com/android/camera/ui/CameraControls.java
index fa9796f..674cb03 100644
--- a/src/com/android/camera/ui/CameraControls.java
+++ b/src/com/android/camera/ui/CameraControls.java
@@ -27,6 +27,7 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
+import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
@@ -87,6 +88,7 @@ public class CameraControls extends RotatableLayout {
private TextView mRemainingPhotosText;
private int mCurrentRemaining = -1;
private int mOrientation;
+ private final Rect mInsets = new Rect();
private int mPreviewRatio;
private int mTopMargin = 0;
@@ -282,20 +284,31 @@ public class CameraControls extends RotatableLayout {
}
@Override
+ protected boolean fitSystemWindows(Rect insets) {
+ mInsets.set(insets);
+ return false;
+ }
+
+ @Override
public void onLayout(boolean changed, int l, int t, int r, int b) {
Log.d(TAG, String.format("onLayout changed=%b l=%d t=%d r=%d b=%d", changed, l, t, r, b));
super.onLayout(changed, l, t, r, b);
+ r -= mInsets.right;
+ b -= mInsets.bottom;
+
ViewGroup.LayoutParams lpTop = mTopBar.getLayoutParams();
lpTop.height = mTopMargin;
mTopBar.setLayoutParams(lpTop);
mTopBar.layout(l, t, r, mTopMargin);
ViewGroup.LayoutParams lpBottom = mBottomBar.getLayoutParams();
- lpBottom.height = mBottomMargin;
+ lpBottom.width = r - l + mInsets.right;
+ lpBottom.height = mBottomMargin + mInsets.bottom;
mBottomBar.setLayoutParams(lpBottom);
- mBottomBar.layout(l, b - mBottomMargin, r, b);
+ mBottomBar.setPadding(0, 0, mInsets.right, mInsets.bottom);
+ mBottomBar.layout(l, b - mBottomMargin, r + mInsets.right, b + mInsets.bottom);
setLocation(r - l, b - t);
diff --git a/src/com/android/camera/ui/CameraRootView.java b/src/com/android/camera/ui/CameraRootView.java
index 42eebaa..92ac21e 100644
--- a/src/com/android/camera/ui/CameraRootView.java
+++ b/src/com/android/camera/ui/CameraRootView.java
@@ -17,9 +17,7 @@
package com.android.camera.ui;
import android.annotation.SuppressLint;
-import android.app.Activity;
import android.content.Context;
-import android.content.res.Configuration;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
@@ -28,7 +26,6 @@ import android.view.View;
import android.widget.FrameLayout;
import com.android.camera.util.ApiHelper;
-import com.android.camera.util.CameraUtil;
@SuppressLint("NewApi")
public class CameraRootView extends FrameLayout {
@@ -37,10 +34,10 @@ public class CameraRootView extends FrameLayout {
private int mBottomMargin = 0;
private int mLeftMargin = 0;
private int mRightMargin = 0;
- private final Rect mCurrentInsets = new Rect(0, 0, 0, 0);
- private int mOffset = 0;
private Object mDisplayListener;
private MyDisplayListener mListener;
+ private Rect mLastInsets = new Rect();
+ private Rect mTmpRect = new Rect();
public interface MyDisplayListener {
public void onDisplayChanged();
@@ -51,26 +48,18 @@ public class CameraRootView extends FrameLayout {
initDisplayListener();
}
- @Override
- protected boolean fitSystemWindows(Rect insets) {
- // insets include status bar, navigation bar, etc
- // In this case, we are only concerned with the size of nav bar
- if (mCurrentInsets.equals(insets)) {
- // Local copy of the insets is up to date. No need to do anything.
- return false;
+ public void redoFitSystemWindows() {
+ if (mLastInsets.left != 0 || mLastInsets.right != 0
+ || mLastInsets.top != 0 || mLastInsets.bottom != 0) {
+ Rect insets = new Rect(mLastInsets);
+ fitSystemWindows(insets);
}
+ }
- if (mOffset == 0) {
- if (insets.bottom > 0) {
- mOffset = insets.bottom;
- } else if (insets.right > 0) {
- mOffset = insets.right;
- }
- }
- mCurrentInsets.set(insets);
- // Make sure onMeasure will be called to adapt to the new insets.
- requestLayout();
- return false;
+ @Override
+ protected boolean fitSystemWindows(Rect insets) {
+ mLastInsets.set(insets);
+ return super.fitSystemWindows(insets);
}
public void initDisplayListener() {
@@ -101,6 +90,40 @@ public class CameraRootView extends FrameLayout {
mListener = listener;
}
+ public Rect getInsetsForOrientation(int orientation) {
+ switch (orientation) {
+ case 90:
+ mTmpRect.set(mLastInsets.top, mLastInsets.right,
+ mLastInsets.bottom, mLastInsets.left);
+ break;
+ case 180:
+ mTmpRect.set(mLastInsets.right, mLastInsets.bottom,
+ mLastInsets.left, mLastInsets.top);
+ break;
+ case 270:
+ mTmpRect.set(mLastInsets.bottom, mLastInsets.left,
+ mLastInsets.top, mLastInsets.right);
+ break;
+ default:
+ mTmpRect.set(mLastInsets);
+ break;
+ }
+
+ return mTmpRect;
+ }
+
+ public Rect getClientRectForOrientation(int orientation) {
+ Rect result = getInsetsForOrientation(orientation);
+ if (orientation == 90 || orientation == 270) {
+ result.right = getHeight() - result.right;
+ result.bottom = getWidth() - result.bottom;
+ } else {
+ result.right = getWidth() - result.right;
+ result.bottom = getHeight() - result.bottom;
+ }
+ return result;
+ }
+
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
@@ -118,78 +141,4 @@ public class CameraRootView extends FrameLayout {
.unregisterDisplayListener((DisplayListener) mDisplayListener);
}
}
-/*
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int rotation = CameraUtil.getDisplayRotation((Activity) getContext());
- // all the layout code assumes camera device orientation to be portrait
- // adjust rotation for landscape
- int orientation = getResources().getConfiguration().orientation;
- int camOrientation = (rotation % 180 == 0) ? Configuration.ORIENTATION_PORTRAIT
- : Configuration.ORIENTATION_LANDSCAPE;
- if (camOrientation != orientation) {
- rotation = (rotation + 90) % 360;
- }
- // calculate margins
- mLeftMargin = 0;
- mRightMargin = 0;
- mBottomMargin = 0;
- mTopMargin = 0;
- switch (rotation) {
- case 0:
- mBottomMargin += mOffset;
- break;
- case 90:
- mRightMargin += mOffset;
- break;
- case 180:
- mTopMargin += mOffset;
- break;
- case 270:
- mLeftMargin += mOffset;
- break;
- }
- if (mCurrentInsets != null) {
- if (mCurrentInsets.right > 0) {
- // navigation bar on the right
- mRightMargin = mRightMargin > 0 ? mRightMargin : mCurrentInsets.right;
- } else {
- // navigation bar on the bottom
- mBottomMargin = mBottomMargin > 0 ? mBottomMargin : mCurrentInsets.bottom;
- }
- }
- // make sure all the children are resized
- super.onMeasure(widthMeasureSpec - mLeftMargin - mRightMargin,
- heightMeasureSpec - mTopMargin - mBottomMargin);
- setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
- }
-
- @Override
- public void onLayout(boolean changed, int l, int t, int r, int b) {
- r -= l;
- b -= t;
- l = 0;
- t = 0;
- int orientation = getResources().getConfiguration().orientation;
- // Lay out children
- for (int i = 0; i < getChildCount(); i++) {
- View v = getChildAt(i);
- if (v instanceof CameraControls) {
- // Lay out camera controls to center on the short side of the screen
- // so that they stay in place during rotation
- int width = v.getMeasuredWidth();
- int height = v.getMeasuredHeight();
- if (orientation == Configuration.ORIENTATION_PORTRAIT) {
- int left = (l + r - width) / 2;
- v.layout(left, t + mTopMargin, left + width, b - mBottomMargin);
- } else {
- int top = (t + b - height) / 2;
- v.layout(l + mLeftMargin, top, r - mRightMargin, top + height);
- }
- } else {
- v.layout(l + mLeftMargin, t + mTopMargin, r - mRightMargin, b - mBottomMargin);
- }
- }
- }
-*/
}
diff --git a/src/com/android/camera/ui/ListMenu.java b/src/com/android/camera/ui/ListMenu.java
index cb11a80..bf6f420 100644
--- a/src/com/android/camera/ui/ListMenu.java
+++ b/src/com/android/camera/ui/ListMenu.java
@@ -20,6 +20,7 @@
package com.android.camera.ui;
import android.content.Context;
+import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
@@ -29,6 +30,7 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
+import android.widget.Space;
import com.android.camera.ListPreference;
import com.android.camera.PreferenceGroup;
@@ -40,16 +42,17 @@ import java.util.ArrayList;
import java.util.List;
/* A popup window that contains several camera settings. */
-public class ListMenu extends ListView
- implements ListMenuItem.Listener,
- AdapterView.OnItemClickListener,
- ListSubMenu.Listener {
+public class ListMenu extends ListView implements
+ ListMenuItem.Listener, ListSubMenu.Listener,
+ AdapterView.OnItemClickListener, RotateLayout.Child {
+
@SuppressWarnings("unused")
private static final String TAG = "ListMenu";
private int mHighlighted = -1;
private Listener mListener;
private SettingsManager mSettingsManager;
private ArrayList<ListPreference> mListItem = new ArrayList<ListPreference>();
+ private View mHeader, mFooter;
// Keep track of which setting items are disabled
// e.g. White balance will be disabled when scene mode is set to non-auto
@@ -95,18 +98,13 @@ public class ListMenu extends ListView
mOffString = context.getString(R.string.setting_off);
}
- private int getSettingLayoutId(ListPreference pref) {
- return R.layout.list_menu_item;
- }
-
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ListPreference pref = mListItem.get(position);
- int viewLayoutId = getSettingLayoutId(pref);
ListMenuItem view = (ListMenuItem) convertView;
view = (ListMenuItem)
- mInflater.inflate(viewLayoutId, parent, false);
+ mInflater.inflate(R.layout.list_menu_item, parent, false);
view.initialize(pref); // no init for restore one
view.setSettingChangedListener(ListMenu.this);
@@ -141,6 +139,32 @@ public class ListMenu extends ListView
mListener = listener;
}
+ @Override
+ public void onApplyWindowInsets(Rect insets, int rootWidth, int rootHeight) {
+ if (mHeader == null) {
+ mHeader = new Space(getContext());
+ addHeaderView(mHeader);
+ setHeaderDividersEnabled(false);
+ mFooter = new Space(getContext());
+ addFooterView(mFooter);
+ setFooterDividersEnabled(false);
+ }
+
+ boolean largerThanRoot =
+ getPreCalculatedHeight() - insets.top - insets.bottom > rootHeight;
+ adjustViewHeight(mHeader, largerThanRoot ? insets.top : 0);
+ adjustViewHeight(mFooter, largerThanRoot ? insets.bottom : 0);
+ }
+
+ private void adjustViewHeight(View view, int height) {
+ ViewGroup.LayoutParams lp = view.getLayoutParams();
+ if (lp == null) {
+ lp = generateDefaultLayoutParams();
+ }
+ lp.height = height;
+ view.setLayoutParams(lp);
+ }
+
public ListMenu(Context context, AttributeSet attrs) {
super(context, attrs);
}
@@ -258,7 +282,8 @@ public class ListMenu extends ListView
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
- if (mListener != null) {
+ position -= getHeaderViewsCount();
+ if (mListener != null && position < mListItem.size()) {
resetHighlight();
ListPreference pref = mListItem.get(position);
mHighlighted = position;
@@ -268,6 +293,12 @@ public class ListMenu extends ListView
}
+ private int getPreCalculatedHeight() {
+ int count = getAdapter().getCount();
+ return count * (int) getContext().getResources().getDimension(R.dimen.setting_row_height)
+ + (count - 1) * getDividerHeight();
+ }
+
public void reloadPreference() {
int count = getChildCount();
for (int i = 0; i < count; i++) {
diff --git a/src/com/android/camera/ui/ListMenuItem.java b/src/com/android/camera/ui/ListMenuItem.java
index b051fdd..80b6bdd 100644
--- a/src/com/android/camera/ui/ListMenuItem.java
+++ b/src/com/android/camera/ui/ListMenuItem.java
@@ -22,7 +22,7 @@ import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
-import android.widget.RelativeLayout;
+import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ImageView;
@@ -40,7 +40,7 @@ import org.codeaurora.snapcam.R;
* Other setting popup window includes several InLineSettingItem items with
* different types if possible.
*/
-public class ListMenuItem extends RelativeLayout {
+public class ListMenuItem extends LinearLayout {
private static final String TAG = "ListMenuItem";
private Listener mListener;
protected ListPreference mPreference;
diff --git a/src/com/android/camera/ui/ListSubMenu.java b/src/com/android/camera/ui/ListSubMenu.java
index a425c76..04da7bc 100644
--- a/src/com/android/camera/ui/ListSubMenu.java
+++ b/src/com/android/camera/ui/ListSubMenu.java
@@ -29,11 +29,13 @@ import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
+import android.widget.Space;
import com.android.camera.IconListPreference;
import com.android.camera.ListPreference;
@@ -45,10 +47,11 @@ import org.codeaurora.snapcam.R;
// the entries will contain both text and icons. Otherwise, entries will be
// shown in text.
public class ListSubMenu extends ListView implements
- AdapterView.OnItemClickListener {
+ RotateLayout.Child, AdapterView.OnItemClickListener {
private static final String TAG = "ListPrefSettingPopup";
private ListPreference mPreference;
private Listener mListener;
+ private View mHeader, mFooter;
private int mY;
static public interface Listener {
@@ -121,7 +124,7 @@ public class ListSubMenu extends ListView implements
public void reloadPreference() {
int index = mPreference.findIndexOfValue(mPreference.getValue());
if (index != -1) {
- setItemChecked(index, true);
+ setItemChecked(index + getHeaderViewsCount(), true);
} else {
Log.e(TAG, "Invalid preference value.");
mPreference.print();
@@ -135,6 +138,10 @@ public class ListSubMenu extends ListView implements
@Override
public void onItemClick(AdapterView<?> parent, View view,
int index, long id) {
+ index -= getHeaderViewsCount();
+ if (index < 0 || index >= getAdapter().getCount()) {
+ return;
+ }
mPreference.setValueIndex(index);
if (mListener != null) {
mListener.onListPrefChanged(mPreference);
@@ -146,6 +153,33 @@ public class ListSubMenu extends ListView implements
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
}
+ @Override
+ public void onApplyWindowInsets(Rect insets, int rootWidth, int rootHeight) {
+ if (mHeader == null) {
+ mHeader = new Space(getContext());
+ addHeaderView(mHeader);
+ setHeaderDividersEnabled(false);
+ mFooter = new Space(getContext());
+ addFooterView(mFooter);
+ setFooterDividersEnabled(false);
+ reloadPreference();
+ }
+
+ boolean largerThanRoot =
+ getPreCalculatedHeight() - insets.top - insets.bottom > rootHeight;
+ adjustViewHeight(mHeader, largerThanRoot ? insets.top : 0);
+ adjustViewHeight(mFooter, largerThanRoot ? insets.bottom : 0);
+ }
+
+ private void adjustViewHeight(View view, int height) {
+ ViewGroup.LayoutParams lp = view.getLayoutParams();
+ if (lp == null) {
+ lp = generateDefaultLayoutParams();
+ }
+ lp.height = height;
+ view.setLayoutParams(lp);
+ }
+
public int getPreCalculatedHeight() {
int count = getAdapter().getCount();
return count * (int) getContext().getResources().getDimension(R.dimen.setting_row_height)
diff --git a/src/com/android/camera/ui/RenderOverlay.java b/src/com/android/camera/ui/RenderOverlay.java
index 8e2f445..5f9b7ae 100644
--- a/src/com/android/camera/ui/RenderOverlay.java
+++ b/src/com/android/camera/ui/RenderOverlay.java
@@ -18,6 +18,7 @@ package com.android.camera.ui;
import android.content.Context;
import android.graphics.Canvas;
+import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
@@ -48,6 +49,7 @@ public class RenderOverlay extends FrameLayout {
// reverse list of touch clients
private List<Renderer> mTouchClients;
private int[] mPosition = new int[2];
+ private final Rect mInsets = new Rect();
public RenderOverlay(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -69,13 +71,15 @@ public class RenderOverlay extends FrameLayout {
if (renderer.handlesTouch()) {
mTouchClients.add(0, renderer);
}
- renderer.layout(getLeft(), getTop(), getRight(), getBottom());
+ renderer.layout(mRenderView.getLeft(), mRenderView.getTop(),
+ mRenderView.getRight(), mRenderView.getBottom());
}
public void addRenderer(int pos, Renderer renderer) {
mClients.add(pos, renderer);
renderer.setOverlay(this);
- renderer.layout(getLeft(), getTop(), getRight(), getBottom());
+ renderer.layout(mRenderView.getLeft(), mRenderView.getTop(),
+ mRenderView.getRight(), mRenderView.getBottom());
}
public void remove(Renderer renderer) {
@@ -88,6 +92,24 @@ public class RenderOverlay extends FrameLayout {
}
@Override
+ protected boolean fitSystemWindows(Rect insets) {
+ if (!mInsets.equals(insets)) {
+ mInsets.set(insets);
+ // Make sure onMeasure will be called to adapt to the new insets.
+ requestLayout();
+ }
+ return false;
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ // make sure all the children are resized - insets include status bar,
+ // navigation bar, etc, but in this case, we are only concerned with the size of nav bar
+ super.onMeasure(widthMeasureSpec - mInsets.right, heightMeasureSpec - mInsets.bottom);
+ setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
+ }
+
+ @Override
public boolean dispatchTouchEvent(MotionEvent m) {
if (mGestures != null) {
if (!mGestures.isEnabled()) return false;
diff --git a/src/com/android/camera/ui/RotateLayout.java b/src/com/android/camera/ui/RotateLayout.java
index e394aba..d322b69 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());
+ }
+ }
}