diff options
Diffstat (limited to 'src/com/android/camera/ui')
17 files changed, 284 insertions, 147 deletions
diff --git a/src/com/android/camera/ui/AbstractIndicatorButton.java b/src/com/android/camera/ui/AbstractIndicatorButton.java index a661586..0ff7b19 100644 --- a/src/com/android/camera/ui/AbstractIndicatorButton.java +++ b/src/com/android/camera/ui/AbstractIndicatorButton.java @@ -106,10 +106,10 @@ public abstract class AbstractIndicatorButton extends RotateImageView implements } @Override - public void setDegree(int degree) { - super.setDegree(degree); + public void setOrientation(int orientation) { + super.setOrientation(orientation); if (mPopup != null) { - mPopup.setOrientation(degree); + mPopup.setOrientation(orientation); } } diff --git a/src/com/android/camera/ui/ControlPanelLayout.java b/src/com/android/camera/ui/ControlPanelLayout.java index f85d955..24efb8b 100644 --- a/src/com/android/camera/ui/ControlPanelLayout.java +++ b/src/com/android/camera/ui/ControlPanelLayout.java @@ -16,7 +16,9 @@ package com.android.camera.ui; +import android.app.Activity; import android.content.Context; +import android.content.pm.ActivityInfo; import android.util.AttributeSet; import android.util.Log; import android.widget.RelativeLayout; @@ -25,8 +27,7 @@ import android.widget.RelativeLayout; * A layout which handles the the width of the control panel, which contains * the shutter button, thumbnail, front/back camera picker, and mode picker. * The purpose of this is to have a consistent width of control panel in camera, - * camcorder, and panorama modes. The control panel can also be GONE and the - * preview can expand to full-screen in panorama. + * camcorder, and panorama modes. */ public class ControlPanelLayout extends RelativeLayout { private static final String TAG = "ControlPanelLayout"; @@ -39,29 +40,43 @@ public class ControlPanelLayout extends RelativeLayout { protected void onMeasure(int widthSpec, int heightSpec) { int widthSpecSize = MeasureSpec.getSize(widthSpec); int heightSpecSize = MeasureSpec.getSize(heightSpec); - int widthMode = MeasureSpec.getMode(widthSpec); - int measuredWidth = 0; + int measuredSize = 0; + int mode, longSideSize, shortSideSize, specSize; - if (widthSpecSize > 0 && heightSpecSize > 0 && widthMode == MeasureSpec.AT_MOST) { + boolean isLandscape = (((Activity) getContext()).getRequestedOrientation() + == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + + if (isLandscape) { + mode = MeasureSpec.getMode(widthSpec); + longSideSize = widthSpecSize; + shortSideSize = heightSpecSize; + specSize = widthSpecSize; + } else { + mode = MeasureSpec.getMode(heightSpec); + longSideSize = heightSpecSize; + shortSideSize = widthSpecSize; + specSize = heightSpecSize; + } + + if (widthSpecSize > 0 && heightSpecSize > 0 && mode == MeasureSpec.AT_MOST) { // Calculate how big 4:3 preview occupies. Then deduct it from the // width of the parent. - measuredWidth = (int) (widthSpecSize - heightSpecSize / 3.0 * 4.0 - 16); + measuredSize = (int) (longSideSize - shortSideSize / 3.0 * 4.0); } else { - Log.e(TAG, "layout_width of ControlPanelLayout should be wrap_content"); + Log.e(TAG, "layout_xxx of ControlPanelLayout should be wrap_content"); } - // Make sure the width is bigger than the minimum width. - int minWidth = getSuggestedMinimumWidth(); - if (minWidth > measuredWidth) { - measuredWidth = minWidth; + // The width cannot be bigger than the constraint. + if (mode == MeasureSpec.AT_MOST && measuredSize > specSize) { + measuredSize = specSize; } - // The width cannot be bigger than the constraint. - if (widthMode == MeasureSpec.AT_MOST && measuredWidth > widthSpecSize) { - measuredWidth = widthSpecSize; + if (isLandscape) { + widthSpec = MeasureSpec.makeMeasureSpec(measuredSize, MeasureSpec.EXACTLY); + } else { + heightSpec = MeasureSpec.makeMeasureSpec(measuredSize, MeasureSpec.EXACTLY); } - super.onMeasure(MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY), - heightSpec); + super.onMeasure(widthSpec, heightSpec); } } diff --git a/src/com/android/camera/ui/EffectSettingPopup.java b/src/com/android/camera/ui/EffectSettingPopup.java index c4a4d49..a0f9be0 100644 --- a/src/com/android/camera/ui/EffectSettingPopup.java +++ b/src/com/android/camera/ui/EffectSettingPopup.java @@ -180,11 +180,19 @@ public class EffectSettingPopup extends AbstractSettingPopup implements @Override public void onItemClick(AdapterView<?> parent, View view, int index, long id) { + String value; if (parent == mSillyFacesGrid) { - String value = (String) mSillyFacesItem.get(index).get("value"); - mPreference.setValue(value); + value = (String) mSillyFacesItem.get(index).get("value"); } else if (parent == mBackgroundGrid) { - String value = (String) mBackgroundItem.get(index).get("value"); + value = (String) mBackgroundItem.get(index).get("value"); + } else { + return; + } + + // Tapping the selected effect will deselect it (clear effects). + if (value.equals(mPreference.getValue())) { + mPreference.setValue(mNoEffect); + } else { mPreference.setValue(value); } reloadPreference(); diff --git a/src/com/android/camera/ui/FaceView.java b/src/com/android/camera/ui/FaceView.java index 9018886..ed59682 100644 --- a/src/com/android/camera/ui/FaceView.java +++ b/src/com/android/camera/ui/FaceView.java @@ -29,7 +29,7 @@ import android.util.AttributeSet; import android.util.Log; import android.view.View; -public class FaceView extends View implements FocusIndicator { +public class FaceView extends View implements FocusIndicator, Rotatable { private final String TAG = "FaceView"; private final boolean LOGV = false; // The value for android.hardware.Camera.setDisplayOrientation. diff --git a/src/com/android/camera/ui/IndicatorControl.java b/src/com/android/camera/ui/IndicatorControl.java index 86b0cc9..cac38b8 100644 --- a/src/com/android/camera/ui/IndicatorControl.java +++ b/src/com/android/camera/ui/IndicatorControl.java @@ -35,7 +35,7 @@ import java.util.ArrayList; * A view that contains camera setting indicators. */ public abstract class IndicatorControl extends RelativeLayout implements - IndicatorButton.Listener, OtherSettingsPopup.Listener { + IndicatorButton.Listener, OtherSettingsPopup.Listener, Rotatable { private static final String TAG = "IndicatorControl"; public static final int MODE_CAMERA = 0; public static final int MODE_VIDEO = 1; @@ -45,7 +45,7 @@ public abstract class IndicatorControl extends RelativeLayout implements protected CameraPicker mCameraPicker; private PreferenceGroup mPreferenceGroup; - private int mDegree = 0; + private int mOrientation = 0; protected int mCurrentMode = MODE_CAMERA; @@ -61,15 +61,13 @@ public abstract class IndicatorControl extends RelativeLayout implements super(context, attrs); } - public void setDegree(int degree) { - mDegree = degree; + public void setOrientation(int orientation) { + mOrientation = orientation; int count = getChildCount(); for (int i = 0 ; i < count ; ++i) { View view = getChildAt(i); - if (view instanceof RotateImageView) { - ((RotateImageView) view).setDegree(degree); - } else if (view instanceof ZoomControl) { - ((ZoomControl) view).setDegree(degree); + if (view instanceof Rotatable) { + ((Rotatable) view).setOrientation(orientation); } } } diff --git a/src/com/android/camera/ui/IndicatorControlBar.java b/src/com/android/camera/ui/IndicatorControlBar.java index 6c2151d..8ab61fd 100644 --- a/src/com/android/camera/ui/IndicatorControlBar.java +++ b/src/com/android/camera/ui/IndicatorControlBar.java @@ -87,20 +87,19 @@ public class IndicatorControlBar extends IndicatorControl implements int count = getChildCount(); if (count == 0) return; - int width = right - left; + int height = bottom - top; - // First indicator will be CameraPicker if exists. - if (mCameraPicker != null) { - mCameraPicker.layout(0, padding, width, padding + width); - } + mSecondLevelIcon.layout(0, 0, height, height); // Layout the zoom control if required. - int offset = padding + width; // the padding and the icon height + int offset = padding + height; // the padding and the icon height if (mZoomControl != null) { - mZoomControl.layout(0, offset, width, bottom - top - offset); + mZoomControl.layout(offset, 0, right - left - offset, height); } - mSecondLevelIcon.layout(0, bottom - top - offset, width, bottom - top); + if (mCameraPicker != null) { + mCameraPicker.layout(right - left - offset, 0, right - left, height); + } } @Override diff --git a/src/com/android/camera/ui/IndicatorControlBarContainer.java b/src/com/android/camera/ui/IndicatorControlBarContainer.java index 6b60ace..3c907a8 100644 --- a/src/com/android/camera/ui/IndicatorControlBarContainer.java +++ b/src/com/android/camera/ui/IndicatorControlBarContainer.java @@ -43,14 +43,14 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer { public IndicatorControlBarContainer(Context context, AttributeSet attrs) { super(context, attrs); mFadeIn = AnimationUtils.loadAnimation( - context, R.anim.grow_fade_in_from_top); + context, R.anim.first_level_fade_in); mFadeOut = AnimationUtils.loadAnimation( - context, R.anim.shrink_fade_out_from_bottom); + context, R.anim.first_level_fade_out); mFadeOut.setAnimationListener(mAnimationListener); mSecondLevelFadeIn = AnimationUtils.loadAnimation( - context, R.anim.grow_fade_in_from_bottom); + context, R.anim.second_level_fade_in); mSecondLevelFadeOut = AnimationUtils.loadAnimation( - context, R.anim.shrink_fade_out_from_top); + context, R.anim.second_level_fade_out); mSecondLevelFadeOut.setAnimationListener(mAnimationListener); } @@ -75,9 +75,9 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer { secondLevelKeys, secondLevelOtherSettingKeys); } - public void setDegree(int degree) { - mIndicatorControlBar.setDegree(degree); - mSecondLevelIndicatorControlBar.setDegree(degree); + public void setOrientation(int orientation) { + mIndicatorControlBar.setOrientation(orientation); + mSecondLevelIndicatorControlBar.setOrientation(orientation); } @Override diff --git a/src/com/android/camera/ui/IndicatorControlWheel.java b/src/com/android/camera/ui/IndicatorControlWheel.java index af36e11..3b8bea4 100644 --- a/src/com/android/camera/ui/IndicatorControlWheel.java +++ b/src/com/android/camera/ui/IndicatorControlWheel.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.Paint; +import android.graphics.Path; import android.graphics.RectF; import android.os.Handler; import android.os.SystemClock; @@ -65,6 +66,7 @@ public class IndicatorControlWheel extends IndicatorControl implements private static final int TIME_LAPSE_ARC_WIDTH = 6; private final int HIGHLIGHT_COLOR; + private final int HIGHLIGHT_FAN_COLOR; private final int TIME_LAPSE_ARC_COLOR; // The center of the shutter button. @@ -115,6 +117,7 @@ public class IndicatorControlWheel extends IndicatorControl implements super(context, attrs); Resources resources = context.getResources(); HIGHLIGHT_COLOR = resources.getColor(R.color.review_control_pressed_color); + HIGHLIGHT_FAN_COLOR = resources.getColor(R.color.review_control_pressed_fan_color); TIME_LAPSE_ARC_COLOR = resources.getColor(R.color.time_lapse_arc); setWillNotDraw(false); @@ -135,9 +138,7 @@ public class IndicatorControlWheel extends IndicatorControl implements } } - @Override - public void onClick(View view) { - if (view == mZoomIcon) return; + private void changeIndicatorsLevel() { mPressedIndex = -1; dismissSettingPopup(); mInAnimation = true; @@ -145,6 +146,12 @@ public class IndicatorControlWheel extends IndicatorControl implements requestLayout(); } + @Override + public void onClick(View view) { + if (view == mZoomIcon) return; + changeIndicatorsLevel(); + } + public void initialize(Context context, PreferenceGroup group, boolean isZoomSupported, String[] keys, String[] otherSettingKeys) { mShutterButtonRadius = IndicatorControlWheelContainer.SHUTTER_BUTTON_RADIUS; @@ -291,7 +298,6 @@ public class IndicatorControlWheel extends IndicatorControl implements double increment = Math.toRadians(expectedAngle) - mChildRadians[mSecondLevelStartIndex]; for (int i = 0 ; i < getChildCount(); ++i) mChildRadians[i] += increment; - requestLayout(); } @Override @@ -309,7 +315,7 @@ public class IndicatorControlWheel extends IndicatorControl implements // The icons are spreaded on the left side of the shutter button. for (int i = 0; i < getChildCount(); ++i) { View view = getChildAt(i); - if (!view.isEnabled()) continue; + // We still need to show the disabled indicators in the second level. double radian = mChildRadians[i]; double startVisibleRadians = mInAnimation ? mStartVisibleRadians[1] @@ -317,8 +323,9 @@ public class IndicatorControlWheel extends IndicatorControl implements double endVisibleRadians = mInAnimation ? mEndVisibleRadians[1] : mEndVisibleRadians[mCurrentLevel]; - if ((radian < (startVisibleRadians - HIGHLIGHT_RADIANS / 2)) || - (radian > (endVisibleRadians + HIGHLIGHT_RADIANS / 2))) { + if ((!view.isEnabled() && (mCurrentLevel == 0)) + || (radian < (startVisibleRadians - HIGHLIGHT_RADIANS / 2)) + || (radian > (endVisibleRadians + HIGHLIGHT_RADIANS / 2))) { view.setVisibility(View.GONE); continue; } @@ -415,19 +422,35 @@ public class IndicatorControlWheel extends IndicatorControl implements @Override protected void onDraw(Canvas canvas) { - // Draw highlight. - float delta = mStrokeWidth * 0.5f; - float radius = (float) (mWheelRadius + mStrokeWidth * 0.5 + EDGE_STROKE_WIDTH); - mBackgroundRect.set(mCenterX - radius, mCenterY - radius, mCenterX + radius, - mCenterY + radius); - int selectedIndex = getSelectedIndicatorIndex(); // Draw the highlight arc if an indicator is selected or being pressed. - if (selectedIndex >= 0) { + if (selectedIndex >= 0) { int degree = (int) Math.toDegrees(mChildRadians[selectedIndex]); + float innerR = (float) mShutterButtonRadius; + float outerR = (float) (mShutterButtonRadius + mStrokeWidth + + EDGE_STROKE_WIDTH * 0.5); + + // Construct the path of the fan-shaped semi-transparent area. + Path fanPath = new Path(); + mBackgroundRect.set(mCenterX - innerR, mCenterY - innerR, + mCenterX + innerR, mCenterY + innerR); + fanPath.arcTo(mBackgroundRect, -degree + HIGHLIGHT_DEGREES / 2, + -HIGHLIGHT_DEGREES); + mBackgroundRect.set(mCenterX - outerR, mCenterY - outerR, + mCenterX + outerR, mCenterY + outerR); + fanPath.arcTo(mBackgroundRect, -degree - HIGHLIGHT_DEGREES / 2, + HIGHLIGHT_DEGREES); + fanPath.close(); + mBackgroundPaint.setStrokeWidth(HIGHLIGHT_WIDTH); - mBackgroundPaint.setStrokeCap(Paint.Cap.ROUND); + mBackgroundPaint.setStrokeCap(Paint.Cap.SQUARE); + mBackgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE); + mBackgroundPaint.setColor(HIGHLIGHT_FAN_COLOR); + canvas.drawPath(fanPath, mBackgroundPaint); + + // Draw the highlight edge + mBackgroundPaint.setStyle(Paint.Style.STROKE); mBackgroundPaint.setColor(HIGHLIGHT_COLOR); canvas.drawArc(mBackgroundRect, -degree - HIGHLIGHT_DEGREES / 2, HIGHLIGHT_DEGREES, false, mBackgroundPaint); @@ -492,4 +515,10 @@ public class IndicatorControlWheel extends IndicatorControl implements invalidate(); } } + + public void dismissSecondLevelIndicator() { + if (mCurrentLevel == 1) { + changeIndicatorsLevel(); + } + } } diff --git a/src/com/android/camera/ui/IndicatorControlWheelContainer.java b/src/com/android/camera/ui/IndicatorControlWheelContainer.java index 14539da..a10136b 100644 --- a/src/com/android/camera/ui/IndicatorControlWheelContainer.java +++ b/src/com/android/camera/ui/IndicatorControlWheelContainer.java @@ -191,9 +191,9 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer { } @Override - public void setDegree(int degree) { - mIndicatorControlWheel.setDegree(degree); - mZoomControlWheel.setDegree(degree); + public void setOrientation(int orientation) { + mIndicatorControlWheel.setOrientation(orientation); + mZoomControlWheel.setOrientation(orientation); } public void startTimeLapseAnimation(int timeLapseInterval, long startTime) { @@ -223,6 +223,6 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer { @Override public void dismissSecondLevelIndicator() { - // TODO: back to first-level indicator set. + mIndicatorControlWheel.dismissSecondLevelIndicator(); } } diff --git a/src/com/android/camera/ui/OneRowGridView.java b/src/com/android/camera/ui/OneRowGridView.java new file mode 100644 index 0000000..5e37d35 --- /dev/null +++ b/src/com/android/camera/ui/OneRowGridView.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2011 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 com.android.camera.R; +import com.android.camera.Util; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.GridView; + +public class OneRowGridView extends GridView { + public OneRowGridView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + // Once we know the number of children in this view, we have to set + // the correct width and height for containing the icons in one row. + int n = getChildCount(); + if (n == 0) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } else { + setMeasuredDimension((n * getChildAt(0).getMeasuredWidth()), + getMeasuredHeight()); + } + } +} diff --git a/src/com/android/camera/ui/RightAlignedHorizontalScrollView.java b/src/com/android/camera/ui/RightAlignedHorizontalScrollView.java new file mode 100644 index 0000000..cd4c5f5 --- /dev/null +++ b/src/com/android/camera/ui/RightAlignedHorizontalScrollView.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2011 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.content.Context; +import android.view.View; +import android.util.AttributeSet; +import android.widget.HorizontalScrollView; + +public class RightAlignedHorizontalScrollView extends HorizontalScrollView { + + public RightAlignedHorizontalScrollView(Context context) { + super(context); + } + + public RightAlignedHorizontalScrollView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + super.onLayout(changed, l, t, r, b); + if (changed) { + // Get the width of the child, i.e. the LinearLayout, and scroll to + // the rightmost position. + View child = getChildAt(0); + if (child != null) scrollTo(child.getWidth(), 0); + } + } +} diff --git a/src/com/android/camera/ui/RotateImageView.java b/src/com/android/camera/ui/RotateImageView.java index 390d705..f47a26b 100644 --- a/src/com/android/camera/ui/RotateImageView.java +++ b/src/com/android/camera/ui/RotateImageView.java @@ -16,8 +16,6 @@ package com.android.camera.ui; -import com.android.camera.ui.Rotatable; - import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -66,12 +64,8 @@ public class RotateImageView extends ColorFilterImageView implements Rotatable { return mTargetDegree; } - public void setOrientation(int orientation) { - setDegree(orientation); - } - // Rotate the view counter-clockwise - public void setDegree(int degree) { + public void setOrientation(int degree) { // make sure in the range of [0, 359] degree = degree >= 0 ? degree % 360 : degree % 360 + 360; if (degree == mTargetDegree) return; diff --git a/src/com/android/camera/ui/RotateLayout.java b/src/com/android/camera/ui/RotateLayout.java index 24815f8..e66e71a 100644 --- a/src/com/android/camera/ui/RotateLayout.java +++ b/src/com/android/camera/ui/RotateLayout.java @@ -16,8 +16,6 @@ package com.android.camera.ui; -import com.android.camera.ui.Rotatable; - import android.content.Context; import android.util.AttributeSet; import android.view.View; diff --git a/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java b/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java index c9037d9..1fb9a80 100644 --- a/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java +++ b/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java @@ -39,7 +39,7 @@ public class SecondLevelIndicatorControlBar extends IndicatorControl implements private View mDivider; // the divider line private View mIndicatorHighlight; // the side highlight bar private View mPopupedIndicator; - int mDegree = 0; + int mOrientation = 0; int mSelectedIndex = -1; // There are some views in the ViewGroup before adding the indicator buttons, // such as Close icon, divider line and the hightlight bar, we need to @@ -64,7 +64,7 @@ public class SecondLevelIndicatorControlBar extends IndicatorControl implements setPreferenceGroup(group); mNonIndicatorButtonCount = getChildCount(); addControls(keys, otherSettingKeys); - if (mDegree != 0) setDegree(mDegree); + if (mOrientation != 0) setOrientation(mOrientation); } public void onClick(View view) { @@ -73,20 +73,20 @@ public class SecondLevelIndicatorControlBar extends IndicatorControl implements OnIndicatorEventListener.EVENT_LEAVE_SECOND_LEVEL_INDICATOR_BAR); } - private int getTouchViewIndex(int y, int height) { + private int getTouchViewIndex(int x, int width) { // If the current touch location is on close icon and above. - if (y < mCloseIcon.getBottom()) return indexOfChild(mCloseIcon); + if (x > mCloseIcon.getLeft()) return indexOfChild(mCloseIcon); // Calculate if the touch event is on the indicator buttons. int count = getChildCount(); if (count == mNonIndicatorButtonCount) return -1; // The baseline will be the first indicator button's top minus spacing. View firstIndicatorButton = getChildAt(mNonIndicatorButtonCount); - int baselineY = firstIndicatorButton.getTop() - (ICON_SPACING / 2); - if (y < baselineY) return -1; - int iconHeight = firstIndicatorButton.getMeasuredHeight(); - int buttonRange = iconHeight + ICON_SPACING; - return (mNonIndicatorButtonCount + (y - baselineY) / buttonRange); + int baselineX = firstIndicatorButton.getRight() + (ICON_SPACING / 2); + if (x > baselineX) return -1; + int iconWidth = firstIndicatorButton.getMeasuredWidth(); + int buttonRange = iconWidth + ICON_SPACING; + return (mNonIndicatorButtonCount + ((baselineX - x) / buttonRange)); } @Override @@ -98,12 +98,12 @@ public class SecondLevelIndicatorControlBar extends IndicatorControl implements double x = (double) event.getX(); double y = (double) event.getY(); - int height = getHeight(); - if (height == 0) return false; // the event is sent before onMeasure() - if (x > getWidth()) x = getWidth(); - if (y >= height) y = height - 1; + int width = getWidth(); + if (width == 0) return false; // the event is sent before onMeasure() + if (x > width) x = width; + if (y >= getHeight()) y = getHeight() - 1; - int index = getTouchViewIndex((int) y, height); + int index = getTouchViewIndex((int) x, width); if (index == -1) return true; View b = getChildAt(index); b.dispatchTouchEvent(event); @@ -151,9 +151,9 @@ public class SecondLevelIndicatorControlBar extends IndicatorControl implements } @Override - public void setDegree(int degree) { - mDegree = degree; - super.setDegree(degree); + public void setOrientation(int orientation) { + mOrientation = orientation; + super.setOrientation(orientation); } @Override @@ -163,26 +163,26 @@ public class SecondLevelIndicatorControlBar extends IndicatorControl implements if (count == 0) return; int width = right - left; int height = bottom - top; - int iconHeight = mCloseIcon.getMeasuredHeight(); - int padding = getPaddingTop(); - - // The first icon is close button. - int offsetY = padding; - mCloseIcon.layout(0, padding, width, (padding + iconHeight)); - - // And layout the divider line. - offsetY += (iconHeight + padding); - mDivider.layout(padding, offsetY, - (width - padding), (offsetY + mDivider.getMeasuredHeight())); + int iconWidth = mCloseIcon.getMeasuredWidth(); + int padding = getPaddingLeft(); // Layout from the last icon up. - int startY = height - iconHeight - padding; - int decrement = iconHeight + ICON_SPACING; + int offsetX = padding; + int increment = iconWidth + ICON_SPACING; for (int i = count - 1; i >= mNonIndicatorButtonCount; --i) { - getChildAt(i).layout(0, startY, width, startY + iconHeight); - startY -= decrement; + getChildAt(i).layout(offsetX, 0, offsetX + iconWidth, height); + offsetX += increment; } + // And layout the divider line. + offsetX = width - iconWidth - 2 * padding; + mDivider.layout(offsetX, padding, (offsetX + mDivider.getMeasuredWidth()), + (height - padding)); + + offsetX = width - iconWidth - padding; + // The first icon is close button. + mCloseIcon.layout(offsetX, 0, (offsetX + iconWidth), height); + // Hightlight the selected indicator if exists. if (mPopupedIndicator == null) { mIndicatorHighlight.setVisibility(View.GONE); @@ -190,9 +190,9 @@ public class SecondLevelIndicatorControlBar extends IndicatorControl implements mIndicatorHighlight.setVisibility(View.VISIBLE); // Keep the top and bottom of the hightlight the same as // the 'active' indicator button. - mIndicatorHighlight.layout(0, mPopupedIndicator.getTop(), - mIndicatorHighlight.getLayoutParams().width, - mPopupedIndicator.getBottom()); + mIndicatorHighlight.layout(mPopupedIndicator.getLeft(), 0, + mPopupedIndicator.getRight(), + mIndicatorHighlight.getLayoutParams().height); } } diff --git a/src/com/android/camera/ui/SharePopup.java b/src/com/android/camera/ui/SharePopup.java index de78f66..134b7c0 100644 --- a/src/com/android/camera/ui/SharePopup.java +++ b/src/com/android/camera/ui/SharePopup.java @@ -23,6 +23,7 @@ import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; @@ -38,7 +39,7 @@ import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ImageView; -import android.widget.ListView; +import android.widget.GridView; import android.widget.PopupWindow; import android.widget.RelativeLayout; import android.widget.SimpleAdapter; @@ -50,7 +51,7 @@ import java.util.Map; // A popup window that contains a big thumbnail and a list of apps to share. public class SharePopup extends PopupWindow implements View.OnClickListener, - View.OnTouchListener, AdapterView.OnItemClickListener { + View.OnTouchListener, AdapterView.OnItemClickListener, Rotatable { private static final String TAG = "SharePopup"; private static final String ADAPTER_COLUMN_ICON = "icon"; private Context mContext; @@ -65,7 +66,7 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, // A view that contains a list of application icons and the share view. private View mRootView; // The list of the application icons. - private ListView mShareList; + private GridView mShareList; // A rotated view that contains the thumbnail. private RotateLayout mThumbnailRotateLayout; private RotateLayout mGotoGalleryRotate; @@ -114,8 +115,7 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, // This is required because popup window is full screen. sharePopup.setOnTouchListener(this); mThumbnailRotateLayout = (RotateLayout) sharePopup.findViewById(R.id.thumbnail_rotate_layout); - mShareList = (ListView) sharePopup.findViewById(R.id.share_list); - mShareList.setDivider(null); + mShareList = (GridView) sharePopup.findViewById(R.id.share_list); mThumbnail = (ImageView) sharePopup.findViewById(R.id.thumbnail); mThumbnail.setImageBitmap(bitmap); mShareView = (ViewGroup) sharePopup.findViewById(R.id.share_view); @@ -279,10 +279,19 @@ public class SharePopup extends PopupWindow implements View.OnClickListener, items.add(map); mComponent.add(component); } + + // On phone UI, we have to know how many icons in the grid view before + // the view is measured. + if (((Activity) mContext).getRequestedOrientation() + == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { + mShareList.setNumColumns(items.size()); + } + SimpleAdapter listItemAdapter = new MySimpleAdapter(mContext, items, R.layout.share_icon, new String[] {ADAPTER_COLUMN_ICON}, new int[] {R.id.icon}); + listItemAdapter.setViewBinder(mViewBinder); mShareList.setAdapter(listItemAdapter); mShareList.setOnItemClickListener(this); diff --git a/src/com/android/camera/ui/ZoomControl.java b/src/com/android/camera/ui/ZoomControl.java index 1809d18..f2971cd 100644 --- a/src/com/android/camera/ui/ZoomControl.java +++ b/src/com/android/camera/ui/ZoomControl.java @@ -29,7 +29,7 @@ import android.widget.RelativeLayout; * A view that contains camera zoom control which could adjust the zoom in/out * if the camera supports zooming. */ -public abstract class ZoomControl extends RelativeLayout { +public abstract class ZoomControl extends RelativeLayout implements Rotatable { // The states of zoom button. public static final int ZOOM_IN = 0; public static final int ZOOM_OUT = 1; @@ -42,7 +42,7 @@ public abstract class ZoomControl extends RelativeLayout { protected ImageView mZoomOut; protected ImageView mZoomSlider; protected int mSliderPosition = 0; - protected int mDegree; + protected int mOrientation; private Handler mHandler; public interface OnZoomChangedListener { @@ -208,13 +208,13 @@ public abstract class ZoomControl extends RelativeLayout { return true; } - public void setDegree(int degree) { - mDegree = degree; + public void setOrientation(int orientation) { + mOrientation = orientation; int count = getChildCount(); for (int i = 0 ; i < count ; ++i) { View view = getChildAt(i); if (view instanceof RotateImageView) { - ((RotateImageView) view).setDegree(degree); + ((RotateImageView) view).setOrientation(orientation); } } } diff --git a/src/com/android/camera/ui/ZoomControlBar.java b/src/com/android/camera/ui/ZoomControlBar.java index 08042d4..4e572cf 100644 --- a/src/com/android/camera/ui/ZoomControlBar.java +++ b/src/com/android/camera/ui/ZoomControlBar.java @@ -36,9 +36,9 @@ public class ZoomControlBar extends ZoomControl { private View mBar; private boolean mStartChanging; private int mSliderLength; - private int mHeight; - private int mIconHeight; - private int mTotalIconHeight; + private int mWidth; + private int mIconWidth; + private int mTotalIconWidth; public ZoomControlBar(Context context, AttributeSet attrs) { super(context, attrs); @@ -53,16 +53,16 @@ public class ZoomControlBar extends ZoomControl { mBar.setActivated(activated); } - private int getSliderPosition(int y) { + private int getSliderPosition(int x) { // Calculate the absolute offset of the slider in the zoom control bar. // For left-hand users, as the device is rotated for 180 degree for // landscape mode, the zoom-in bottom should be on the top, so the // position should be reversed. int pos; // the relative position in the zoom slider bar - if (mDegree == 180) { - pos = y - mTotalIconHeight; + if (mOrientation == 90) { + pos = mWidth - mTotalIconWidth - x; } else { - pos = mHeight - mTotalIconHeight - y; + pos = x - mTotalIconWidth; } if (pos < 0) pos = 0; if (pos > mSliderLength) pos = mSliderLength; @@ -71,15 +71,15 @@ public class ZoomControlBar extends ZoomControl { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { - mHeight = h; - mIconHeight = mZoomIn.getMeasuredHeight(); - mTotalIconHeight = mIconHeight + ICON_SPACING; - mSliderLength = mHeight - (2 * mTotalIconHeight); + mWidth = w; + mIconWidth = mZoomIn.getMeasuredWidth(); + mTotalIconWidth = mIconWidth + ICON_SPACING; + mSliderLength = mWidth - (2 * mTotalIconWidth); } @Override public boolean dispatchTouchEvent(MotionEvent event) { - if (!isEnabled() || (mHeight == 0)) return false; + if (!isEnabled() || (mWidth == 0)) return false; int action = event.getAction(); switch (action) { @@ -94,7 +94,7 @@ public class ZoomControlBar extends ZoomControl { setActivated(true); mStartChanging = false; case MotionEvent.ACTION_MOVE: - int pos = getSliderPosition((int) event.getY()); + int pos = getSliderPosition((int) event.getX()); if (!mStartChanging) { // Make sure the movement is large enough before we start // changing the zoom. @@ -114,18 +114,18 @@ public class ZoomControlBar extends ZoomControl { } @Override - public void setDegree(int degree) { + public void setOrientation(int orientation) { // layout for the left-hand camera control - if ((degree == 180) || (mDegree == 180)) requestLayout(); - super.setDegree(degree); + if ((orientation == 90) || (mOrientation == 90)) requestLayout(); + super.setOrientation(orientation); } @Override protected void onLayout( boolean changed, int left, int top, int right, int bottom) { if (mZoomMax == 0) return; - int width = right - left; - mBar.layout(0, mTotalIconHeight, width, mHeight - mTotalIconHeight); + int height = bottom - top; + mBar.layout(mTotalIconWidth, 0, mWidth - mTotalIconWidth, height); // For left-hand users, as the device is rotated for 180 degree, // the zoom-in button should be on the top. int pos; // slider position @@ -135,18 +135,18 @@ public class ZoomControlBar extends ZoomControl { } else { sliderPosition = (int) ((double) mSliderLength * mZoomIndex / mZoomMax); } - if (mDegree == 180) { - mZoomOut.layout(0, 0, width, mIconHeight); - mZoomIn.layout(0, mHeight - mIconHeight, width, mHeight); - pos = mBar.getTop() + sliderPosition; + if (mOrientation == 90) { + mZoomIn.layout(0, 0, mIconWidth, height); + mZoomOut.layout(mWidth - mIconWidth, 0, mWidth, height); + pos = mBar.getRight() - sliderPosition; } else { - mZoomIn.layout(0, 0, width, mIconHeight); - mZoomOut.layout(0, mHeight - mIconHeight, width, mHeight); - pos = mBar.getBottom() - sliderPosition; + mZoomOut.layout(0, 0, mIconWidth, height); + mZoomIn.layout(mWidth - mIconWidth, 0, mWidth, height); + pos = mBar.getLeft() + sliderPosition; } - int sliderHeight = mZoomSlider.getMeasuredHeight(); - mZoomSlider.layout(0, (pos - sliderHeight / 2), - width, (pos + sliderHeight / 2)); + int sliderWidth = mZoomSlider.getMeasuredWidth(); + mZoomSlider.layout((pos - sliderWidth / 2), 0, + (pos + sliderWidth / 2), height); } @Override |