From e7e0c028d568c1a4c3e88ed75411b8b41c5aec69 Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Wed, 12 Feb 2014 11:14:08 -0800 Subject: [PATCH] Center mode drawer in uncovered preview Also align the mode drawer to the left edge of the preview Bug: 12974095 Bug: 12971043 Change-Id: Ic7b9cb95352cba52d3ccf6c09667476f2ea04d69 --- res/layout/mode_list_layout.xml | 2 +- src/com/android/camera/app/CameraAppUI.java | 4 +- src/com/android/camera/ui/ModeListView.java | 80 +++++++++++++++++++++-------- 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/res/layout/mode_list_layout.xml b/res/layout/mode_list_layout.xml index 6847b089e..2da4a35e1 100644 --- a/res/layout/mode_list_layout.xml +++ b/res/layout/mode_list_layout.xml @@ -26,7 +26,7 @@ mListView.getWidth() || y < 0 || y > mListView.getHeight()) { return false; } @@ -368,6 +385,11 @@ public class ModeListView extends FrameLayout mListBackgroundColor = getResources().getColor(R.color.mode_list_background); } + public CameraAppUI.UncoveredPreviewAreaSizeChangedListener + getUncoveredPreviewAreaSizeChangedListener() { + return mUncoveredPreviewAreaSizeChangedListener; + } + /** * Sets the alpha on the list background. This is called whenever the list * is scrolling or animating, so that background can adjust its dimness. @@ -418,7 +440,7 @@ public class ModeListView extends FrameLayout } mTotalModes = mSupportedModes.size(); initializeModeSelectorItems(); - mSettingsButton = findViewById(R.id.settings_button); + mSettingsButton = (SettingsButton) findViewById(R.id.settings_button); mSettingsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -447,6 +469,16 @@ public class ModeListView extends FrameLayout ModeSelectorItem selectorItem = (ModeSelectorItem) inflater.inflate(R.layout.mode_selector, null); mListView.addView(selectorItem); + // Sets the top padding of the top item to 0. + if (i == 0) { + selectorItem.setPadding(selectorItem.getPaddingLeft(), 0, + selectorItem.getPaddingRight(), selectorItem.getPaddingBottom()); + } + // Sets the bottom padding of the bottom item to 0. + if (i == mTotalModes - 1) { + selectorItem.setPadding(selectorItem.getPaddingLeft(), selectorItem.getPaddingTop(), + selectorItem.getPaddingRight(), 0); + } int modeId = getModeIndex(i); selectorItem.setHighlightColor(getResources() @@ -580,9 +612,9 @@ public class ModeListView extends FrameLayout */ @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - centerModeDrawerInPreview(MeasureSpec.getSize(widthMeasureSpec), - MeasureSpec.getSize(heightMeasureSpec)); super.onMeasure(widthMeasureSpec, heightMeasureSpec); + centerModeDrawerInUncoveredPreview(MeasureSpec.getSize(widthMeasureSpec), + MeasureSpec.getSize(heightMeasureSpec)); } @Override @@ -653,8 +685,8 @@ public class ModeListView extends FrameLayout */ private int getFocusItem(float x, float y) { // Convert coordinates into child view's coordinates. - x -= mListView.getLeft(); - y -= mListView.getTop(); + x -= mListView.getX(); + y -= mListView.getY(); for (int i = 0; i < mModeSelectorItems.length; i++) { if (y <= mModeSelectorItems[i].getBottom()) { @@ -668,7 +700,7 @@ public class ModeListView extends FrameLayout public void onVisibilityChanged(View v, int visibility) { super.onVisibilityChanged(v, visibility); if (visibility == VISIBLE) { - centerModeDrawerInPreview(getMeasuredWidth(), getMeasuredHeight()); + centerModeDrawerInUncoveredPreview(getMeasuredWidth(), getMeasuredHeight()); // Highlight current module if (mModeSwitchListener != null) { int modeId = mModeSwitchListener.getCurrentModeIndex(); @@ -695,21 +727,27 @@ public class ModeListView extends FrameLayout } /** - * Center mode drawer in camera preview. + * Center mode drawer in the portion of camera preview that is not covered by + * bottom bar. */ - private void centerModeDrawerInPreview(int measuredWidth, int measuredHeight) { + // TODO: Combine SettingsButton logic into here if UX design does not change + // for another week. + private void centerModeDrawerInUncoveredPreview(int measuredWidth, int measuredHeight) { // Assuming the preview is centered in the space aside from bottom bar. - float previewAreaWidth = mPreviewArea.right + mPreviewArea.left; - float previewAreaHeight = mPreviewArea.top + mPreviewArea.bottom; - if (measuredWidth > measuredHeight) { - // Landscape. - int previewWidth = (int) Math.max(previewAreaHeight, previewAreaWidth); - setPadding(0, 0, measuredWidth - previewWidth, 0); + float previewAreaWidth = mUncoveredPreviewArea.right + mUncoveredPreviewArea.left; + float previewAreaHeight = mUncoveredPreviewArea.top + mUncoveredPreviewArea.bottom; + if (measuredWidth > measuredHeight && previewAreaWidth < previewAreaHeight + || measuredWidth < measuredHeight && previewAreaWidth > previewAreaHeight) { + // Cached preview area is stale, update mode drawer position on next + // layout pass. + mAdjustPositionWhenUncoveredPreviewAreaChanges = true; } else { - // Portrait. - int previewHeight = (int) Math.max(previewAreaHeight, previewAreaWidth); - setPadding(0, 0, 0, measuredHeight - previewHeight); + // Align left: + mListView.setTranslationX(mUncoveredPreviewArea.left); + // Align center vertical: + mListView.setTranslationY(mUncoveredPreviewArea.centerY() + - mListView.getMeasuredHeight() / 2); } } -- 2.11.0