diff options
author | Alan Newberger <alann@google.com> | 2014-09-23 00:35:30 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-09-23 00:35:30 +0000 |
commit | 8f1ffed79db5d7e17f56501b5d62157846fb55bd (patch) | |
tree | c6b76826b7447f141095926649a924ec3904500a | |
parent | 82da5e9543cf97c5e25a78b90ae94ea9cb32f5ee (diff) | |
parent | b2b0e02cb5f0aba8fed9389193fa98150da75efc (diff) | |
download | android_packages_apps_Camera2-8f1ffed79db5d7e17f56501b5d62157846fb55bd.tar.gz android_packages_apps_Camera2-8f1ffed79db5d7e17f56501b5d62157846fb55bd.tar.bz2 android_packages_apps_Camera2-8f1ffed79db5d7e17f56501b5d62157846fb55bd.zip |
am b2b0e02c: Clean up unused code
* commit 'b2b0e02cb5f0aba8fed9389193fa98150da75efc':
Clean up unused code
-rw-r--r-- | src/com/android/camera/PreviewGestures.java | 204 | ||||
-rw-r--r-- | src/com/android/camera/ui/OverlayRenderer.java | 97 | ||||
-rw-r--r-- | src/com/android/camera/ui/PieItem.java | 170 | ||||
-rw-r--r-- | src/com/android/camera/ui/PieMenuButton.java | 62 | ||||
-rw-r--r-- | src/com/android/camera/ui/PieRenderer.java | 1093 | ||||
-rw-r--r-- | src/com/android/camera/ui/RenderOverlay.java | 220 | ||||
-rw-r--r-- | src/com/android/camera/ui/ZoomRenderer.java | 166 |
7 files changed, 0 insertions, 2012 deletions
diff --git a/src/com/android/camera/PreviewGestures.java b/src/com/android/camera/PreviewGestures.java deleted file mode 100644 index 8ab4a7fc8..000000000 --- a/src/com/android/camera/PreviewGestures.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera; - -import android.view.GestureDetector; -import android.view.MotionEvent; -import android.view.ScaleGestureDetector; -import android.view.View; - -import com.android.camera.debug.Log; -import com.android.camera.ui.PieRenderer; -import com.android.camera.ui.RenderOverlay; -import com.android.camera.ui.ZoomRenderer; - -/* PreviewGestures disambiguates touch events received on RenderOverlay - * and dispatch them to the proper recipient (i.e. zoom renderer or pie renderer). - * Touch events on CameraControls will be handled by framework. - * */ -public class PreviewGestures - implements ScaleGestureDetector.OnScaleGestureListener { - - private static final Log.Tag TAG = new Log.Tag("PreviewGestures"); - - private static final int MODE_NONE = 0; - private static final int MODE_ZOOM = 2; - - public static final int DIR_UP = 0; - public static final int DIR_DOWN = 1; - public static final int DIR_LEFT = 2; - public static final int DIR_RIGHT = 3; - - private final SingleTapListener mTapListener; - private RenderOverlay mOverlay; - private final PieRenderer mPie; - private final ZoomRenderer mZoom; - private MotionEvent mDown; - private MotionEvent mCurrent; - private final ScaleGestureDetector mScale; - private int mMode; - private boolean mZoomEnabled; - private boolean mEnabled; - private boolean mZoomOnly; - private final GestureDetector mGestureDetector; - - private final GestureDetector.SimpleOnGestureListener mGestureListener = new GestureDetector.SimpleOnGestureListener() { - @Override - public void onLongPress (MotionEvent e) { - // Open pie - if (!mZoomOnly && mPie != null && !mPie.showsItems()) { - openPie(); - } - } - - @Override - public boolean onSingleTapUp (MotionEvent e) { - // Tap to focus when pie is not open - if (mPie == null || !mPie.showsItems()) { - mTapListener.onSingleTapUp(null, (int) e.getX(), (int) e.getY()); - return true; - } - return false; - } - - @Override - public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - if (e1 == null) { - // e1 can be null if for some cases. - return false; - } - if (mZoomOnly || mMode == MODE_ZOOM) return false; - int deltaX = (int) (e1.getX() - e2.getX()); - int deltaY = (int) (e1.getY() - e2.getY()); - if (deltaY > 2 * deltaX && deltaY > -2 * deltaX) { - // Open pie on swipe up - if (mPie != null && !mPie.showsItems()) { - openPie(); - return true; - } - } - return false; - } - }; - - public interface SingleTapListener { - public void onSingleTapUp(View v, int x, int y); - } - - public PreviewGestures(CameraActivity ctx, SingleTapListener tapListener, - ZoomRenderer zoom, PieRenderer pie) { - mTapListener = tapListener; - mPie = pie; - mZoom = zoom; - mMode = MODE_NONE; - mScale = new ScaleGestureDetector(ctx, this); - mEnabled = true; - mGestureDetector = new GestureDetector(mGestureListener); - } - - public void setRenderOverlay(RenderOverlay overlay) { - mOverlay = overlay; - } - - public void setEnabled(boolean enabled) { - mEnabled = enabled; - } - - public void setZoomEnabled(boolean enable) { - mZoomEnabled = enable; - } - - public void setZoomOnly(boolean zoom) { - mZoomOnly = zoom; - } - - public boolean isEnabled() { - return mEnabled; - } - - public boolean dispatchTouch(MotionEvent m) { - if (!mEnabled) { - return false; - } - mCurrent = m; - if (MotionEvent.ACTION_DOWN == m.getActionMasked()) { - mMode = MODE_NONE; - mDown = MotionEvent.obtain(m); - } - - // If pie is open, redirects all the touch events to pie. - if (mPie != null && mPie.isOpen()) { - return sendToPie(m); - } - - // If pie is not open, send touch events to gesture detector and scale - // listener to recognize the gesture. - mGestureDetector.onTouchEvent(m); - if (mZoom != null) { - mScale.onTouchEvent(m); - if (MotionEvent.ACTION_POINTER_DOWN == m.getActionMasked()) { - mMode = MODE_ZOOM; - if (mZoomEnabled) { - // Start showing zoom UI as soon as there is a second finger down - mZoom.onScaleBegin(mScale); - } - } else if (MotionEvent.ACTION_POINTER_UP == m.getActionMasked()) { - mZoom.onScaleEnd(mScale); - } - } - return true; - } - - private MotionEvent makeCancelEvent(MotionEvent m) { - MotionEvent c = MotionEvent.obtain(m); - c.setAction(MotionEvent.ACTION_CANCEL); - return c; - } - - private void openPie() { - mGestureDetector.onTouchEvent(makeCancelEvent(mDown)); - mScale.onTouchEvent(makeCancelEvent(mDown)); - mOverlay.directDispatchTouch(mDown, mPie); - } - - private boolean sendToPie(MotionEvent m) { - return mOverlay.directDispatchTouch(m, mPie); - } - - // OnScaleGestureListener implementation - @Override - public boolean onScale(ScaleGestureDetector detector) { - return mZoom.onScale(detector); - } - - @Override - public boolean onScaleBegin(ScaleGestureDetector detector) { - if (mPie == null || !mPie.isOpen()) { - mMode = MODE_ZOOM; - mGestureDetector.onTouchEvent(makeCancelEvent(mCurrent)); - if (!mZoomEnabled) return false; - return mZoom.onScaleBegin(detector); - } - return false; - } - - @Override - public void onScaleEnd(ScaleGestureDetector detector) { - mZoom.onScaleEnd(detector); - } -} - diff --git a/src/com/android/camera/ui/OverlayRenderer.java b/src/com/android/camera/ui/OverlayRenderer.java deleted file mode 100644 index 110e10fcd..000000000 --- a/src/com/android/camera/ui/OverlayRenderer.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2012 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.graphics.Canvas; -import android.view.MotionEvent; - -import com.android.camera.debug.Log; - -public abstract class OverlayRenderer implements RenderOverlay.Renderer { - - private static final Log.Tag TAG = new Log.Tag("OverlayRenderer"); - protected RenderOverlay mOverlay; - - protected int mLeft, mTop, mRight, mBottom; - - protected boolean mVisible; - - public void setVisible(boolean vis) { - mVisible = vis; - update(); - } - - public boolean isVisible() { - return mVisible; - } - - // default does not handle touch - @Override - public boolean handlesTouch() { - return false; - } - - @Override - public boolean onTouchEvent(MotionEvent evt) { - return false; - } - - public abstract void onDraw(Canvas canvas); - - public void draw(Canvas canvas) { - if (mVisible) { - onDraw(canvas); - } - } - - @Override - public void setOverlay(RenderOverlay overlay) { - mOverlay = overlay; - } - - @Override - public void layout(int left, int top, int right, int bottom) { - mLeft = left; - mRight = right; - mTop = top; - mBottom = bottom; - } - - protected Context getContext() { - if (mOverlay != null) { - return mOverlay.getContext(); - } else { - return null; - } - } - - public int getWidth() { - return mRight - mLeft; - } - - public int getHeight() { - return mBottom - mTop; - } - - protected void update() { - if (mOverlay != null) { - mOverlay.update(); - } - } - -} diff --git a/src/com/android/camera/ui/PieItem.java b/src/com/android/camera/ui/PieItem.java deleted file mode 100644 index 47fe06758..000000000 --- a/src/com/android/camera/ui/PieItem.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2012 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.graphics.Canvas; -import android.graphics.Path; -import android.graphics.drawable.Drawable; - -import java.util.ArrayList; -import java.util.List; - -/** - * Pie menu item - */ -public class PieItem { - - public static interface OnClickListener { - void onClick(PieItem item); - } - - private Drawable mDrawable; - private int level; - - private boolean mSelected; - private boolean mEnabled; - private List<PieItem> mItems; - private Path mPath; - private OnClickListener mOnClickListener; - private float mAlpha; - private CharSequence mLabel; - - // Gray out the view when disabled - private static final float ENABLED_ALPHA = 1; - private static final float DISABLED_ALPHA = (float) 0.3; - private boolean mChangeAlphaWhenDisabled = true; - - public PieItem(Drawable drawable, int level) { - mDrawable = drawable; - this.level = level; - if (drawable != null) { - setAlpha(1f); - } - mEnabled = true; - } - - public void setLabel(CharSequence txt) { - mLabel = txt; - } - - public CharSequence getLabel() { - return mLabel; - } - - public boolean hasItems() { - return mItems != null; - } - - public List<PieItem> getItems() { - return mItems; - } - - public void addItem(PieItem item) { - if (mItems == null) { - mItems = new ArrayList<PieItem>(); - } - mItems.add(item); - } - - public void clearItems() { - mItems = null; - } - - public void setLevel(int level) { - this.level = level; - } - - public void setPath(Path p) { - mPath = p; - } - - public Path getPath() { - return mPath; - } - - public void setChangeAlphaWhenDisabled (boolean enable) { - mChangeAlphaWhenDisabled = enable; - } - - public void setAlpha(float alpha) { - mAlpha = alpha; - mDrawable.setAlpha((int) (255 * alpha)); - } - - public void setEnabled(boolean enabled) { - mEnabled = enabled; - if (mChangeAlphaWhenDisabled) { - if (mEnabled) { - setAlpha(ENABLED_ALPHA); - } else { - setAlpha(DISABLED_ALPHA); - } - } - } - - public boolean isEnabled() { - return mEnabled; - } - - public void setSelected(boolean s) { - mSelected = s; - } - - public boolean isSelected() { - return mSelected; - } - - public int getLevel() { - return level; - } - - - public void setOnClickListener(OnClickListener listener) { - mOnClickListener = listener; - } - - public void performClick() { - if (mOnClickListener != null) { - mOnClickListener.onClick(this); - } - } - - public int getIntrinsicWidth() { - return mDrawable.getIntrinsicWidth(); - } - - public int getIntrinsicHeight() { - return mDrawable.getIntrinsicHeight(); - } - - public void setBounds(int left, int top, int right, int bottom) { - mDrawable.setBounds(left, top, right, bottom); - } - - public void draw(Canvas canvas) { - mDrawable.draw(canvas); - } - - public void setImageResource(Context context, int resId) { - Drawable d = context.getResources().getDrawable(resId).mutate(); - d.setBounds(mDrawable.getBounds()); - mDrawable = d; - setAlpha(mAlpha); - } - -} diff --git a/src/com/android/camera/ui/PieMenuButton.java b/src/com/android/camera/ui/PieMenuButton.java deleted file mode 100644 index 0ad93fa0b..000000000 --- a/src/com/android/camera/ui/PieMenuButton.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.View; - -public class PieMenuButton extends View { - private boolean mPressed; - private boolean mReadyToClick = false; - public PieMenuButton(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - protected void drawableStateChanged() { - super.drawableStateChanged(); - mPressed = isPressed(); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - boolean handled = super.onTouchEvent(event); - if (MotionEvent.ACTION_UP == event.getAction() && mPressed) { - // Perform a customized click as soon as the ACTION_UP event - // is received. The reason for doing this is that Framework - // delays the performClick() call after ACTION_UP. But we do not - // want the delay because it affects an important state change - // for PieRenderer. - mReadyToClick = true; - performClick(); - } - return handled; - } - - @Override - public boolean performClick() { - if (mReadyToClick) { - // We only respond to our customized click which happens right - // after ACTION_UP event is received, with no delay. - mReadyToClick = false; - return super.performClick(); - } - return false; - } -}; diff --git a/src/com/android/camera/ui/PieRenderer.java b/src/com/android/camera/ui/PieRenderer.java deleted file mode 100644 index 935b5f662..000000000 --- a/src/com/android/camera/ui/PieRenderer.java +++ /dev/null @@ -1,1093 +0,0 @@ -/* - * Copyright (C) 2012 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.animation.Animator; -import android.animation.Animator.AnimatorListener; -import android.animation.ValueAnimator; -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.Point; -import android.graphics.PointF; -import android.graphics.RectF; -import android.os.Handler; -import android.os.Message; -import android.util.FloatMath; -import android.view.MotionEvent; -import android.view.ViewConfiguration; -import android.view.animation.Animation; -import android.view.animation.Transformation; - -import com.android.camera.debug.Log; -import com.android.camera.drawable.TextDrawable; -import com.android.camera2.R; - -import java.util.ArrayList; -import java.util.List; - -/** - * An overlay renderer that is used to display focus state and progress state. - */ -public class PieRenderer extends OverlayRenderer - implements FocusIndicator { - - private static final Log.Tag TAG = new Log.Tag("PieRenderer"); - - // Sometimes continuous autofocus starts and stops several times quickly. - // These states are used to make sure the animation is run for at least some - // time. - private volatile int mState; - private ScaleAnimation mAnimation = new ScaleAnimation(); - private static final int STATE_IDLE = 0; - private static final int STATE_FOCUSING = 1; - private static final int STATE_FINISHING = 2; - private static final int STATE_PIE = 8; - - private static final float MATH_PI_2 = (float)(Math.PI / 2); - - private Runnable mDisappear = new Disappear(); - private Animation.AnimationListener mEndAction = new EndAction(); - private static final int SCALING_UP_TIME = 600; - private static final int SCALING_DOWN_TIME = 100; - private static final int DISAPPEAR_TIMEOUT = 200; - private static final int DIAL_HORIZONTAL = 157; - // fade out timings - private static final int PIE_FADE_OUT_DURATION = 600; - - private static final long PIE_FADE_IN_DURATION = 200; - private static final long PIE_XFADE_DURATION = 200; - private static final long PIE_SELECT_FADE_DURATION = 300; - private static final long PIE_OPEN_SUB_DELAY = 400; - private static final long PIE_SLICE_DURATION = 80; - - private static final int MSG_OPEN = 0; - private static final int MSG_CLOSE = 1; - private static final int MSG_OPENSUBMENU = 2; - - protected static float CENTER = (float) Math.PI / 2; - protected static float RAD24 = (float)(24 * Math.PI / 180); - protected static final float SWEEP_SLICE = 0.14f; - protected static final float SWEEP_ARC = 0.23f; - - // geometry - private int mRadius; - private int mRadiusInc; - - // the detection if touch is inside a slice is offset - // inbounds by this amount to allow the selection to show before the - // finger covers it - private int mTouchOffset; - - private List<PieItem> mOpen; - - private Paint mSelectedPaint; - private Paint mSubPaint; - private Paint mMenuArcPaint; - - // touch handling - private PieItem mCurrentItem; - - private Paint mFocusPaint; - private int mSuccessColor; - private int mFailColor; - private int mCircleSize; - private int mFocusX; - private int mFocusY; - private int mCenterX; - private int mCenterY; - private int mArcCenterY; - private int mSliceCenterY; - private int mPieCenterX; - private int mPieCenterY; - private int mSliceRadius; - private int mArcRadius; - private int mArcOffset; - - private int mDialAngle; - private RectF mCircle; - private RectF mDial; - private Point mPoint1; - private Point mPoint2; - private int mStartAnimationAngle; - private boolean mFocused; - private int mInnerOffset; - private int mOuterStroke; - private int mInnerStroke; - private boolean mTapMode; - private boolean mBlockFocus; - private int mTouchSlopSquared; - private Point mDown; - private boolean mOpening; - private ValueAnimator mXFade; - private ValueAnimator mFadeIn; - private ValueAnimator mFadeOut; - private ValueAnimator mSlice; - private volatile boolean mFocusCancelled; - private PointF mPolar = new PointF(); - private TextDrawable mLabel; - private int mDeadZone; - private int mAngleZone; - private float mCenterAngle; - - private Handler mHandler = new Handler() { - public void handleMessage(Message msg) { - switch(msg.what) { - case MSG_OPEN: - if (mListener != null) { - mListener.onPieOpened(mPieCenterX, mPieCenterY); - } - break; - case MSG_CLOSE: - if (mListener != null) { - mListener.onPieClosed(); - } - break; - case MSG_OPENSUBMENU: - onEnterOpen(); - break; - } - - } - }; - - private PieListener mListener; - - static public interface PieListener { - public void onPieOpened(int centerX, int centerY); - public void onPieClosed(); - } - - public void setPieListener(PieListener pl) { - mListener = pl; - } - - public PieRenderer(Context context) { - init(context); - } - - private void init(Context ctx) { - setVisible(false); - mOpen = new ArrayList<PieItem>(); - mOpen.add(new PieItem(null, 0)); - Resources res = ctx.getResources(); - mRadius = (int) res.getDimensionPixelSize(R.dimen.pie_radius_start); - mRadiusInc = (int) res.getDimensionPixelSize(R.dimen.pie_radius_increment); - mCircleSize = mRadius - res.getDimensionPixelSize(R.dimen.focus_radius_offset); - mTouchOffset = (int) res.getDimensionPixelSize(R.dimen.pie_touch_offset); - mSelectedPaint = new Paint(); - mSelectedPaint.setColor(Color.argb(255, 51, 181, 229)); - mSelectedPaint.setAntiAlias(true); - mSubPaint = new Paint(); - mSubPaint.setAntiAlias(true); - mSubPaint.setColor(Color.argb(200, 250, 230, 128)); - mFocusPaint = new Paint(); - mFocusPaint.setAntiAlias(true); - mFocusPaint.setColor(Color.WHITE); - mFocusPaint.setStyle(Paint.Style.STROKE); - mSuccessColor = Color.GREEN; - mFailColor = Color.RED; - mCircle = new RectF(); - mDial = new RectF(); - mPoint1 = new Point(); - mPoint2 = new Point(); - mInnerOffset = res.getDimensionPixelSize(R.dimen.focus_inner_offset); - mOuterStroke = res.getDimensionPixelSize(R.dimen.focus_outer_stroke); - mInnerStroke = res.getDimensionPixelSize(R.dimen.focus_inner_stroke); - mState = STATE_IDLE; - mBlockFocus = false; - mTouchSlopSquared = ViewConfiguration.get(ctx).getScaledTouchSlop(); - mTouchSlopSquared = mTouchSlopSquared * mTouchSlopSquared; - mDown = new Point(); - mMenuArcPaint = new Paint(); - mMenuArcPaint.setAntiAlias(true); - mMenuArcPaint.setColor(Color.argb(140, 255, 255, 255)); - mMenuArcPaint.setStrokeWidth(10); - mMenuArcPaint.setStyle(Paint.Style.STROKE); - mSliceRadius = res.getDimensionPixelSize(R.dimen.pie_item_radius); - mArcRadius = res.getDimensionPixelSize(R.dimen.pie_arc_radius); - mArcOffset = res.getDimensionPixelSize(R.dimen.pie_arc_offset); - mLabel = new TextDrawable(res); - mLabel.setDropShadow(true); - mDeadZone = res.getDimensionPixelSize(R.dimen.pie_deadzone_width); - mAngleZone = res.getDimensionPixelSize(R.dimen.pie_anglezone_width); - } - - private PieItem getRoot() { - return mOpen.get(0); - } - - public boolean showsItems() { - return mTapMode; - } - - public void addItem(PieItem item) { - // add the item to the pie itself - getRoot().addItem(item); - } - - public void clearItems() { - getRoot().clearItems(); - } - - public void showInCenter() { - if ((mState == STATE_PIE) && isVisible()) { - mTapMode = false; - show(false); - } else { - if (mState != STATE_IDLE) { - cancelFocus(); - } - mState = STATE_PIE; - resetPieCenter(); - setCenter(mPieCenterX, mPieCenterY); - mTapMode = true; - show(true); - } - } - - public void hide() { - show(false); - } - - /** - * guaranteed has center set - * @param show - */ - private void show(boolean show) { - if (show) { - if (mXFade != null) { - mXFade.cancel(); - } - mState = STATE_PIE; - // ensure clean state - mCurrentItem = null; - PieItem root = getRoot(); - for (PieItem openItem : mOpen) { - if (openItem.hasItems()) { - for (PieItem item : openItem.getItems()) { - item.setSelected(false); - } - } - } - mLabel.setText(""); - mOpen.clear(); - mOpen.add(root); - layoutPie(); - fadeIn(); - } else { - mState = STATE_IDLE; - mTapMode = false; - if (mXFade != null) { - mXFade.cancel(); - } - if (mLabel != null) { - mLabel.setText(""); - } - } - setVisible(show); - mHandler.sendEmptyMessage(show ? MSG_OPEN : MSG_CLOSE); - } - - public boolean isOpen() { - return mState == STATE_PIE && isVisible(); - } - - private void fadeIn() { - mFadeIn = new ValueAnimator(); - mFadeIn.setFloatValues(0f, 1f); - mFadeIn.setDuration(PIE_FADE_IN_DURATION); - // linear interpolation - mFadeIn.setInterpolator(null); - mFadeIn.addListener(new AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) { - } - - @Override - public void onAnimationEnd(Animator animation) { - mFadeIn = null; - } - - @Override - public void onAnimationRepeat(Animator animation) { - } - - @Override - public void onAnimationCancel(Animator arg0) { - } - }); - mFadeIn.start(); - } - - public void setCenter(int x, int y) { - mPieCenterX = x; - mPieCenterY = y; - mSliceCenterY = y + mSliceRadius - mArcOffset; - mArcCenterY = y - mArcOffset + mArcRadius; - } - - @Override - public void layout(int l, int t, int r, int b) { - super.layout(l, t, r, b); - mCenterX = (r - l) / 2; - mCenterY = (b - t) / 2; - - mFocusX = mCenterX; - mFocusY = mCenterY; - resetPieCenter(); - setCircle(mFocusX, mFocusY); - if (isVisible() && mState == STATE_PIE) { - setCenter(mPieCenterX, mPieCenterY); - layoutPie(); - } - } - - private void resetPieCenter() { - mPieCenterX = mCenterX; - mPieCenterY = (int) (getHeight() - 2.5f * mDeadZone); - } - - private void layoutPie() { - mCenterAngle = getCenterAngle(); - layoutItems(0, getRoot().getItems()); - layoutLabel(getLevel()); - } - - private void layoutLabel(int level) { - int x = mPieCenterX - (int) (FloatMath.sin(mCenterAngle - CENTER) - * (mArcRadius + (level + 2) * mRadiusInc)); - int y = mArcCenterY - mArcRadius - (level + 2) * mRadiusInc; - int w = mLabel.getIntrinsicWidth(); - int h = mLabel.getIntrinsicHeight(); - mLabel.setBounds(x - w/2, y - h/2, x + w/2, y + h/2); - } - - private void layoutItems(int level, List<PieItem> items) { - int extend = 1; - Path path = makeSlice(getDegrees(0) + extend, getDegrees(SWEEP_ARC) - extend, - mArcRadius, mArcRadius + mRadiusInc + mRadiusInc / 4, - mPieCenterX, mArcCenterY - level * mRadiusInc); - final int count = items.size(); - int pos = 0; - for (PieItem item : items) { - // shared between items - item.setPath(path); - float angle = getArcCenter(item, pos, count); - int w = item.getIntrinsicWidth(); - int h = item.getIntrinsicHeight(); - // move views to outer border - int r = mArcRadius + mRadiusInc * 2 / 3; - int x = (int) (r * Math.cos(angle)); - int y = mArcCenterY - (level * mRadiusInc) - (int) (r * Math.sin(angle)) - h / 2; - x = mPieCenterX + x - w / 2; - item.setBounds(x, y, x + w, y + h); - item.setLevel(level); - if (item.hasItems()) { - layoutItems(level + 1, item.getItems()); - } - pos++; - } - } - - private Path makeSlice(float start, float end, int inner, int outer, int cx, int cy) { - RectF bb = - new RectF(cx - outer, cy - outer, cx + outer, - cy + outer); - RectF bbi = - new RectF(cx - inner, cy - inner, cx + inner, - cy + inner); - Path path = new Path(); - path.arcTo(bb, start, end - start, true); - path.arcTo(bbi, end, start - end); - path.close(); - return path; - } - - private float getArcCenter(PieItem item, int pos, int count) { - return getCenter(pos, count, SWEEP_ARC); - } - - private float getSliceCenter(PieItem item, int pos, int count) { - float center = (getCenterAngle() - CENTER) * 0.5f + CENTER; - return center + (count - 1) * SWEEP_SLICE / 2f - - pos * SWEEP_SLICE; - } - - private float getCenter(int pos, int count, float sweep) { - return mCenterAngle + (count - 1) * sweep / 2f - pos * sweep; - } - - private float getCenterAngle() { - float center = CENTER; - if (mPieCenterX < mDeadZone + mAngleZone) { - center = CENTER - (mAngleZone - mPieCenterX + mDeadZone) * RAD24 - / (float) mAngleZone; - } else if (mPieCenterX > getWidth() - mDeadZone - mAngleZone) { - center = CENTER + (mPieCenterX - (getWidth() - mDeadZone - mAngleZone)) * RAD24 - / (float) mAngleZone; - } - return center; - } - - /** - * converts a - * @param angle from 0..PI to Android degrees (clockwise starting at 3 o'clock) - * @return skia angle - */ - private float getDegrees(double angle) { - return (float) (360 - 180 * angle / Math.PI); - } - - private void startFadeOut(final PieItem item) { - if (mFadeIn != null) { - mFadeIn.cancel(); - } - if (mXFade != null) { - mXFade.cancel(); - } - mFadeOut = new ValueAnimator(); - mFadeOut.setFloatValues(1f, 0f); - mFadeOut.setDuration(PIE_FADE_OUT_DURATION); - mFadeOut.addListener(new AnimatorListener() { - @Override - public void onAnimationStart(Animator animator) { - } - - @Override - public void onAnimationEnd(Animator animator) { - item.performClick(); - mFadeOut = null; - deselect(); - show(false); - mOverlay.setAlpha(1); - } - - @Override - public void onAnimationRepeat(Animator animator) { - } - - @Override - public void onAnimationCancel(Animator animator) { - } - - }); - mFadeOut.start(); - } - - // root does not count - private boolean hasOpenItem() { - return mOpen.size() > 1; - } - - // pop an item of the open item stack - private PieItem closeOpenItem() { - PieItem item = getOpenItem(); - mOpen.remove(mOpen.size() -1); - return item; - } - - private PieItem getOpenItem() { - return mOpen.get(mOpen.size() - 1); - } - - // return the children either the root or parent of the current open item - private PieItem getParent() { - return mOpen.get(Math.max(0, mOpen.size() - 2)); - } - - private int getLevel() { - return mOpen.size() - 1; - } - - @Override - public void onDraw(Canvas canvas) { - float alpha = 1; - if (mXFade != null) { - alpha = (Float) mXFade.getAnimatedValue(); - } else if (mFadeIn != null) { - alpha = (Float) mFadeIn.getAnimatedValue(); - } else if (mFadeOut != null) { - alpha = (Float) mFadeOut.getAnimatedValue(); - } - int state = canvas.save(); - if (mFadeIn != null) { - float sf = 0.9f + alpha * 0.1f; - canvas.scale(sf, sf, mPieCenterX, mPieCenterY); - } - if (mState != STATE_PIE) { - drawFocus(canvas); - } - if (mState == STATE_FINISHING) { - canvas.restoreToCount(state); - return; - } - if (mState != STATE_PIE) return; - if (!hasOpenItem() || (mXFade != null)) { - // draw base menu - drawArc(canvas, getLevel(), getParent()); - List<PieItem> items = getParent().getItems(); - final int count = items.size(); - int pos = 0; - for (PieItem item : getParent().getItems()) { - drawItem(Math.max(0, mOpen.size() - 2), pos, count, canvas, item, alpha); - pos++; - } - mLabel.draw(canvas); - } - if (hasOpenItem()) { - int level = getLevel(); - drawArc(canvas, level, getOpenItem()); - List<PieItem> items = getOpenItem().getItems(); - final int count = items.size(); - int pos = 0; - for (PieItem inner : items) { - if (mFadeOut != null) { - drawItem(level, pos, count, canvas, inner, alpha); - } else { - drawItem(level, pos, count, canvas, inner, (mXFade != null) ? (1 - 0.5f * alpha) : 1); - } - pos++; - } - mLabel.draw(canvas); - } - canvas.restoreToCount(state); - } - - private void drawArc(Canvas canvas, int level, PieItem item) { - // arc - if (mState == STATE_PIE) { - final int count = item.getItems().size(); - float start = mCenterAngle + (count * SWEEP_ARC / 2f); - float end = mCenterAngle - (count * SWEEP_ARC / 2f); - int cy = mArcCenterY - level * mRadiusInc; - canvas.drawArc(new RectF(mPieCenterX - mArcRadius, cy - mArcRadius, - mPieCenterX + mArcRadius, cy + mArcRadius), - getDegrees(end), getDegrees(start) - getDegrees(end), false, mMenuArcPaint); - } - } - - private void drawItem(int level, int pos, int count, Canvas canvas, PieItem item, float alpha) { - if (mState == STATE_PIE) { - if (item.getPath() != null) { - int y = mArcCenterY - level * mRadiusInc; - if (item.isSelected()) { - Paint p = mSelectedPaint; - int state = canvas.save(); - float angle = 0; - if (mSlice != null) { - angle = (Float) mSlice.getAnimatedValue(); - } else { - angle = getArcCenter(item, pos, count) - SWEEP_ARC / 2f; - } - angle = getDegrees(angle); - canvas.rotate(angle, mPieCenterX, y); - if (mFadeOut != null) { - p.setAlpha((int)(255 * alpha)); - } - canvas.drawPath(item.getPath(), p); - if (mFadeOut != null) { - p.setAlpha(255); - } - canvas.restoreToCount(state); - } - if (mFadeOut == null) { - alpha = alpha * (item.isEnabled() ? 1 : 0.3f); - // draw the item view - item.setAlpha(alpha); - } - item.draw(canvas); - } - } - } - - @Override - public boolean onTouchEvent(MotionEvent evt) { - float x = evt.getX(); - float y = evt.getY(); - int action = evt.getActionMasked(); - getPolar(x, y, !mTapMode, mPolar); - if (MotionEvent.ACTION_DOWN == action) { - if ((x < mDeadZone) || (x > getWidth() - mDeadZone)) { - return false; - } - mDown.x = (int) evt.getX(); - mDown.y = (int) evt.getY(); - mOpening = false; - if (mTapMode) { - PieItem item = findItem(mPolar); - if ((item != null) && (mCurrentItem != item)) { - mState = STATE_PIE; - onEnter(item); - } - } else { - setCenter((int) x, (int) y); - show(true); - } - return true; - } else if (MotionEvent.ACTION_UP == action) { - if (isVisible()) { - PieItem item = mCurrentItem; - if (mTapMode) { - item = findItem(mPolar); - if (mOpening) { - mOpening = false; - return true; - } - } - if (item == null) { - mTapMode = false; - show(false); - } else if (!mOpening && !item.hasItems()) { - startFadeOut(item); - mTapMode = false; - } else { - mTapMode = true; - } - return true; - } - } else if (MotionEvent.ACTION_CANCEL == action) { - if (isVisible() || mTapMode) { - show(false); - } - deselect(); - mHandler.removeMessages(MSG_OPENSUBMENU); - return false; - } else if (MotionEvent.ACTION_MOVE == action) { - if (pulledToCenter(mPolar)) { - mHandler.removeMessages(MSG_OPENSUBMENU); - if (hasOpenItem()) { - if (mCurrentItem != null) { - mCurrentItem.setSelected(false); - } - closeOpenItem(); - mCurrentItem = null; - } else { - deselect(); - } - mLabel.setText(""); - return false; - } - PieItem item = findItem(mPolar); - boolean moved = hasMoved(evt); - if ((item != null) && (mCurrentItem != item) && (!mOpening || moved)) { - mHandler.removeMessages(MSG_OPENSUBMENU); - // only select if we didn't just open or have moved past slop - if (moved) { - // switch back to swipe mode - mTapMode = false; - } - onEnterSelect(item); - mHandler.sendEmptyMessageDelayed(MSG_OPENSUBMENU, PIE_OPEN_SUB_DELAY); - } - } - return false; - } - - @Override - public boolean isVisible() { - return super.isVisible(); - } - - private boolean pulledToCenter(PointF polarCoords) { - return polarCoords.y < mArcRadius - mRadiusInc; - } - - private boolean inside(PointF polar, PieItem item, int pos, int count) { - float start = getSliceCenter(item, pos, count) - SWEEP_SLICE / 2f; - boolean res = (mArcRadius < polar.y) - && (start < polar.x) - && (start + SWEEP_SLICE > polar.x) - && (!mTapMode || (mArcRadius + mRadiusInc > polar.y)); - return res; - } - - private void getPolar(float x, float y, boolean useOffset, PointF res) { - // get angle and radius from x/y - res.x = (float) Math.PI / 2; - x = x - mPieCenterX; - float y1 = mSliceCenterY - getLevel() * mRadiusInc - y; - float y2 = mArcCenterY - getLevel() * mRadiusInc - y; - res.y = (float) Math.sqrt(x * x + y2 * y2); - if (x != 0) { - res.x = (float) Math.atan2(y1, x); - if (res.x < 0) { - res.x = (float) (2 * Math.PI + res.x); - } - } - res.y = res.y + (useOffset ? mTouchOffset : 0); - } - - private boolean hasMoved(MotionEvent e) { - return mTouchSlopSquared < (e.getX() - mDown.x) * (e.getX() - mDown.x) - + (e.getY() - mDown.y) * (e.getY() - mDown.y); - } - - private void onEnterSelect(PieItem item) { - if (mCurrentItem != null) { - mCurrentItem.setSelected(false); - } - if (item != null && item.isEnabled()) { - moveSelection(mCurrentItem, item); - item.setSelected(true); - mCurrentItem = item; - mLabel.setText(mCurrentItem.getLabel()); - layoutLabel(getLevel()); - } else { - mCurrentItem = null; - } - } - - private void onEnterOpen() { - if ((mCurrentItem != null) && (mCurrentItem != getOpenItem()) && mCurrentItem.hasItems()) { - openCurrentItem(); - } - } - - /** - * enter a slice for a view - * updates model only - * @param item - */ - private void onEnter(PieItem item) { - if (mCurrentItem != null) { - mCurrentItem.setSelected(false); - } - if (item != null && item.isEnabled()) { - item.setSelected(true); - mCurrentItem = item; - mLabel.setText(mCurrentItem.getLabel()); - if ((mCurrentItem != getOpenItem()) && mCurrentItem.hasItems()) { - openCurrentItem(); - layoutLabel(getLevel()); - } - } else { - mCurrentItem = null; - } - } - - private void deselect() { - if (mCurrentItem != null) { - mCurrentItem.setSelected(false); - } - if (hasOpenItem()) { - PieItem item = closeOpenItem(); - onEnter(item); - } else { - mCurrentItem = null; - } - } - - private int getItemPos(PieItem target) { - List<PieItem> items = getOpenItem().getItems(); - return items.indexOf(target); - } - - private int getCurrentCount() { - return getOpenItem().getItems().size(); - } - - private void moveSelection(PieItem from, PieItem to) { - final int count = getCurrentCount(); - final int fromPos = getItemPos(from); - final int toPos = getItemPos(to); - if (fromPos != -1 && toPos != -1) { - float startAngle = getArcCenter(from, getItemPos(from), count) - - SWEEP_ARC / 2f; - float endAngle = getArcCenter(to, getItemPos(to), count) - - SWEEP_ARC / 2f; - mSlice = new ValueAnimator(); - mSlice.setFloatValues(startAngle, endAngle); - // linear interpolater - mSlice.setInterpolator(null); - mSlice.setDuration(PIE_SLICE_DURATION); - mSlice.addListener(new AnimatorListener() { - @Override - public void onAnimationEnd(Animator arg0) { - mSlice = null; - } - - @Override - public void onAnimationRepeat(Animator arg0) { - } - - @Override - public void onAnimationStart(Animator arg0) { - } - - @Override - public void onAnimationCancel(Animator arg0) { - } - }); - mSlice.start(); - } - } - - private void openCurrentItem() { - if ((mCurrentItem != null) && mCurrentItem.hasItems()) { - mOpen.add(mCurrentItem); - layoutLabel(getLevel()); - mOpening = true; - if (mFadeIn != null) { - mFadeIn.cancel(); - } - mXFade = new ValueAnimator(); - mXFade.setFloatValues(1f, 0f); - mXFade.setDuration(PIE_XFADE_DURATION); - // Linear interpolation - mXFade.setInterpolator(null); - final PieItem ci = mCurrentItem; - mXFade.addListener(new AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) { - } - - @Override - public void onAnimationEnd(Animator animation) { - mXFade = null; - ci.setSelected(false); - mOpening = false; - } - - @Override - public void onAnimationRepeat(Animator animation) { - } - - @Override - public void onAnimationCancel(Animator arg0) { - } - }); - mXFade.start(); - } - } - - /** - * @param polar x: angle, y: dist - * @return the item at angle/dist or null - */ - private PieItem findItem(PointF polar) { - // find the matching item: - List<PieItem> items = getOpenItem().getItems(); - final int count = items.size(); - int pos = 0; - for (PieItem item : items) { - if (inside(polar, item, pos, count)) { - return item; - } - pos++; - } - return null; - } - - - @Override - public boolean handlesTouch() { - return true; - } - - // focus specific code - - public void setBlockFocus(boolean blocked) { - mBlockFocus = blocked; - if (blocked) { - clear(); - } - } - - public void setFocus(int x, int y) { - mOverlay.removeCallbacks(mDisappear); - mFocusX = x; - mFocusY = y; - setCircle(mFocusX, mFocusY); - } - - public int getSize() { - return 2 * mCircleSize; - } - - private int getRandomRange() { - return (int)(-60 + 120 * Math.random()); - } - - private void setCircle(int cx, int cy) { - mCircle.set(cx - mCircleSize, cy - mCircleSize, - cx + mCircleSize, cy + mCircleSize); - mDial.set(cx - mCircleSize + mInnerOffset, cy - mCircleSize + mInnerOffset, - cx + mCircleSize - mInnerOffset, cy + mCircleSize - mInnerOffset); - } - - public void drawFocus(Canvas canvas) { - if (mBlockFocus) return; - mFocusPaint.setStrokeWidth(mOuterStroke); - canvas.drawCircle((float) mFocusX, (float) mFocusY, (float) mCircleSize, mFocusPaint); - if (mState == STATE_PIE) return; - int color = mFocusPaint.getColor(); - if (mState == STATE_FINISHING) { - mFocusPaint.setColor(mFocused ? mSuccessColor : mFailColor); - } - mFocusPaint.setStrokeWidth(mInnerStroke); - drawLine(canvas, mDialAngle, mFocusPaint); - drawLine(canvas, mDialAngle + 45, mFocusPaint); - drawLine(canvas, mDialAngle + 180, mFocusPaint); - drawLine(canvas, mDialAngle + 225, mFocusPaint); - canvas.save(); - // rotate the arc instead of its offset to better use framework's shape caching - canvas.rotate(mDialAngle, mFocusX, mFocusY); - canvas.drawArc(mDial, 0, 45, false, mFocusPaint); - canvas.drawArc(mDial, 180, 45, false, mFocusPaint); - canvas.restore(); - mFocusPaint.setColor(color); - } - - private void drawLine(Canvas canvas, int angle, Paint p) { - convertCart(angle, mCircleSize - mInnerOffset, mPoint1); - convertCart(angle, mCircleSize - mInnerOffset + mInnerOffset / 3, mPoint2); - canvas.drawLine(mPoint1.x + mFocusX, mPoint1.y + mFocusY, - mPoint2.x + mFocusX, mPoint2.y + mFocusY, p); - } - - private static void convertCart(int angle, int radius, Point out) { - double a = 2 * Math.PI * (angle % 360) / 360; - out.x = (int) (radius * Math.cos(a) + 0.5); - out.y = (int) (radius * Math.sin(a) + 0.5); - } - - @Override - public void showStart() { - if (mState == STATE_PIE) return; - cancelFocus(); - mStartAnimationAngle = 67; - int range = getRandomRange(); - startAnimation(SCALING_UP_TIME, - false, mStartAnimationAngle, mStartAnimationAngle + range); - mState = STATE_FOCUSING; - } - - @Override - public void showSuccess(boolean timeout) { - if (mState == STATE_FOCUSING) { - startAnimation(SCALING_DOWN_TIME, - timeout, mStartAnimationAngle); - mState = STATE_FINISHING; - mFocused = true; - } - } - - @Override - public void showFail(boolean timeout) { - if (mState == STATE_FOCUSING) { - startAnimation(SCALING_DOWN_TIME, - timeout, mStartAnimationAngle); - mState = STATE_FINISHING; - mFocused = false; - } - } - - private void cancelFocus() { - mFocusCancelled = true; - mOverlay.removeCallbacks(mDisappear); - if (mAnimation != null && !mAnimation.hasEnded()) { - mAnimation.cancel(); - } - mFocusCancelled = false; - mFocused = false; - mState = STATE_IDLE; - } - - public void clear(boolean waitUntilProgressIsHidden) { - if (mState == STATE_PIE) - return; - cancelFocus(); - mOverlay.post(mDisappear); - } - - @Override - public void clear() { - clear(false); - } - - private void startAnimation(long duration, boolean timeout, - float toScale) { - startAnimation(duration, timeout, mDialAngle, - toScale); - } - - private void startAnimation(long duration, boolean timeout, - float fromScale, float toScale) { - setVisible(true); - mAnimation.reset(); - mAnimation.setDuration(duration); - mAnimation.setScale(fromScale, toScale); - mAnimation.setAnimationListener(timeout ? mEndAction : null); - mOverlay.startAnimation(mAnimation); - update(); - } - - private class EndAction implements Animation.AnimationListener { - @Override - public void onAnimationEnd(Animation animation) { - // Keep the focus indicator for some time. - if (!mFocusCancelled && mOverlay != null) { - mOverlay.postDelayed(mDisappear, DISAPPEAR_TIMEOUT); - } - } - - @Override - public void onAnimationRepeat(Animation animation) { - } - - @Override - public void onAnimationStart(Animation animation) { - } - } - - private class Disappear implements Runnable { - @Override - public void run() { - if (mState == STATE_PIE) return; - setVisible(false); - mFocusX = mCenterX; - mFocusY = mCenterY; - mState = STATE_IDLE; - setCircle(mFocusX, mFocusY); - mFocused = false; - } - } - - private class ScaleAnimation extends Animation { - private float mFrom = 1f; - private float mTo = 1f; - - public ScaleAnimation() { - setFillAfter(true); - } - - public void setScale(float from, float to) { - mFrom = from; - mTo = to; - } - - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - mDialAngle = (int)(mFrom + (mTo - mFrom) * interpolatedTime); - } - } - -} diff --git a/src/com/android/camera/ui/RenderOverlay.java b/src/com/android/camera/ui/RenderOverlay.java deleted file mode 100644 index 8daf819a5..000000000 --- a/src/com/android/camera/ui/RenderOverlay.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (C) 2012 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.graphics.Canvas; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.View; -import android.widget.FrameLayout; - -import com.android.camera.PreviewGestures; -import com.android.camera.debug.Log; - -import java.util.ArrayList; -import java.util.List; - -public class RenderOverlay extends FrameLayout { - - private static final Log.Tag TAG = new Log.Tag("RenderOverlay"); - private PreviewGestures.SingleTapListener mTapListener; - - interface Renderer { - - public boolean handlesTouch(); - public boolean onTouchEvent(MotionEvent evt); - public void setOverlay(RenderOverlay overlay); - public void layout(int left, int top, int right, int bottom); - public void draw(Canvas canvas); - - } - - private final RenderView mRenderView; - private final List<Renderer> mClients; - private PreviewGestures mGestures; - // reverse list of touch clients - private final List<Renderer> mTouchClients; - private final int[] mPosition = new int[2]; - - public RenderOverlay(Context context, AttributeSet attrs) { - super(context, attrs); - mRenderView = new RenderView(context); - addView(mRenderView, new LayoutParams(LayoutParams.MATCH_PARENT, - LayoutParams.MATCH_PARENT)); - mClients = new ArrayList<Renderer>(10); - mTouchClients = new ArrayList<Renderer>(10); - setWillNotDraw(false); - } - - public void setGestures(PreviewGestures gestures) { - mGestures = gestures; - } - - public void addRenderer(Renderer renderer) { - mClients.add(renderer); - renderer.setOverlay(this); - if (renderer.handlesTouch()) { - mTouchClients.add(0, renderer); - } - renderer.layout(getLeft(), getTop(), getRight(), getBottom()); - } - - public void addRenderer(int pos, Renderer renderer) { - mClients.add(pos, renderer); - renderer.setOverlay(this); - renderer.layout(getLeft(), getTop(), getRight(), getBottom()); - } - - public void remove(Renderer renderer) { - mClients.remove(renderer); - renderer.setOverlay(null); - } - - public int getClientSize() { - return mClients.size(); - } - - // TODO: Remove this when refactor is done. This is only here temporarily - // to keep pie working before it's replaced with bottom bar. - public void directTouchEventsToPie(MotionEvent ev) { - PieRenderer pie = null; - for (int i = 0; i < mClients.size(); i++) { - if (mClients.get(i) instanceof PieRenderer) { - pie = (PieRenderer) mClients.get(i); - break; - } - } - if (pie!= null && pie.isOpen()) { - pie.onTouchEvent(ev); - } else { - if (mTapListener != null && ev.getActionMasked() == MotionEvent.ACTION_DOWN) { - mTapListener.onSingleTapUp(null, ((int) ev.getX()), ((int) ev.getY())); - } - } - } - - // TODO: Remove this when refactor is done. This is only here temporarily - // to keep pie working before it's replaced with bottom bar. - public void clear() { - mGestures = null; - while (mClients.size() > 0) { - remove(mClients.get(0)); - } - mTouchClients.clear(); - mTapListener = null; - } - - // TODO: Design a touch flow for each module to handle the leftover touch - // events from the app - public void setTapListener(PreviewGestures.SingleTapListener listener) { - mTapListener = listener; - } - - - // Only Gcam is using this right now, which is only using the pie - // menu for the capture progress. - // TODO: migrate all modes to PreviewOverlay. - @Override - public boolean onTouchEvent(MotionEvent ev) { - if (mTapListener != null && ev.getActionMasked() == MotionEvent.ACTION_UP) { - mTapListener.onSingleTapUp(null, ((int) ev.getX()), ((int) ev.getY())); - } - return true; - } - - public boolean directDispatchTouch(MotionEvent m, Renderer target) { - mRenderView.setTouchTarget(target); - boolean res = mRenderView.dispatchTouchEvent(m); - mRenderView.setTouchTarget(null); - return res; - } - - private void adjustPosition() { - getLocationInWindow(mPosition); - } - - public int getWindowPositionX() { - return mPosition[0]; - } - - public int getWindowPositionY() { - return mPosition[1]; - } - - public void update() { - mRenderView.invalidate(); - } - - private class RenderView extends View { - - private Renderer mTouchTarget; - - public RenderView(Context context) { - super(context); - setWillNotDraw(false); - } - - public void setTouchTarget(Renderer target) { - mTouchTarget = target; - } - - @Override - public boolean dispatchTouchEvent(MotionEvent evt) { - if (mGestures == null) { - return false; - } - - if (mTouchTarget != null) { - return mTouchTarget.onTouchEvent(evt); - } - if (mTouchClients != null) { - boolean res = false; - for (Renderer client : mTouchClients) { - res |= client.onTouchEvent(evt); - } - return res; - } - return false; - } - - @Override - public void onLayout(boolean changed, int left, int top, int right, int bottom) { - adjustPosition(); - super.onLayout(changed, left, top, right, bottom); - if (mClients == null) return; - for (Renderer renderer : mClients) { - renderer.layout(left, top, right, bottom); - } - } - - @Override - public void draw(Canvas canvas) { - super.draw(canvas); - if (mClients == null) return; - boolean redraw = false; - for (Renderer renderer : mClients) { - renderer.draw(canvas); - redraw = redraw || ((OverlayRenderer) renderer).isVisible(); - } - if (redraw) { - invalidate(); - } - } - } - -} diff --git a/src/com/android/camera/ui/ZoomRenderer.java b/src/com/android/camera/ui/ZoomRenderer.java deleted file mode 100644 index 2b997b2f4..000000000 --- a/src/com/android/camera/ui/ZoomRenderer.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (C) 2012 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.content.res.Resources; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.view.ScaleGestureDetector; - -import com.android.camera.debug.Log; -import com.android.camera2.R; - -// TODO: remove this; functionality has been moved to PreviewOverlay. -@Deprecated -public class ZoomRenderer extends OverlayRenderer - implements ScaleGestureDetector.OnScaleGestureListener { - - private static final Log.Tag TAG = new Log.Tag("ZoomRenderer"); - - final private int mMinIndex = 0; - private int mMaxIndex; - // Discrete Zoom level [mMinIndex,mMaxIndex]. - private int mCurrentIndex; - // Continuous Zoom level [0,1]. - private float mCurrentFraction; - private double mFingerRadians; - private OnZoomChangedListener mListener; - private final ScaleGestureDetector mDetector; - private final Paint mPaint; - private int mCenterX; - private int mCenterY; - private float mOuterRadius; - private float mInnerRadius; - private final int mZoomStroke; - - public interface OnZoomChangedListener { - void onZoomStart(); - void onZoomEnd(); - void onZoomValueChanged(int index); - } - - public ZoomRenderer(Context ctx) { - Resources res = ctx.getResources(); - mZoomStroke = res.getDimensionPixelSize(R.dimen.zoom_stroke); - mPaint = new Paint(); - mPaint.setAntiAlias(true); - mPaint.setColor(Color.WHITE); - mPaint.setStyle(Paint.Style.STROKE); - mPaint.setStrokeWidth(mZoomStroke); - mPaint.setStrokeCap(Paint.Cap.ROUND); - mDetector = new ScaleGestureDetector(ctx, this); - setVisible(false); - } - - // Set maximum Zoom Index from Module. - public void setZoomMax(int zoomMaxIndex) { - mMaxIndex = zoomMaxIndex; - } - - // Set current Zoom Index from Module. - public void setZoom(int index) { - mCurrentIndex = index; - mCurrentFraction = (float) index / (mMaxIndex - mMinIndex); - } - - // Set Zoom Value to display from Module. - public void setZoomValue(int centiValue) { - // Do nothing. - } - - public void setOnZoomChangeListener(OnZoomChangedListener listener) { - mListener = listener; - } - - @Override - public void layout(int l, int t, int r, int b) { - super.layout(l, t, r, b); - mCenterX = (r - l) / 2; - mCenterY = (b - t) / 2; - // UI will extend from 20% to 80% of maximum inset circle. - float insetCircleRadius = Math.min(getWidth(), getHeight()); - mInnerRadius = insetCircleRadius * 0.12f; - mOuterRadius = insetCircleRadius * 0.38f; - } - - public boolean isScaling() { - return mDetector.isInProgress(); - } - - @Override - public void onDraw(Canvas canvas) { - // Draw background. - mPaint.setAlpha(70); - canvas.drawLine(mCenterX + mInnerRadius * (float) Math.cos(mFingerRadians), - mCenterY - mInnerRadius * (float) Math.sin(mFingerRadians), - mCenterX + mOuterRadius * (float) Math.cos(mFingerRadians), - mCenterY - mOuterRadius * (float) Math.sin(mFingerRadians), mPaint); - canvas.drawLine(mCenterX - mInnerRadius * (float) Math.cos(mFingerRadians), - mCenterY + mInnerRadius * (float) Math.sin(mFingerRadians), - mCenterX - mOuterRadius * (float) Math.cos(mFingerRadians), - mCenterY + mOuterRadius * (float) Math.sin(mFingerRadians), mPaint); - // Draw Zoom progress. - mPaint.setAlpha(255); - float zoomRadius = mInnerRadius + mCurrentFraction * (mOuterRadius - mInnerRadius); - canvas.drawLine(mCenterX + mInnerRadius * (float) Math.cos(mFingerRadians), - mCenterY - mInnerRadius * (float) Math.sin(mFingerRadians), - mCenterX + zoomRadius * (float) Math.cos(mFingerRadians), - mCenterY - zoomRadius * (float) Math.sin(mFingerRadians), mPaint); - canvas.drawLine(mCenterX - mInnerRadius * (float) Math.cos(mFingerRadians), - mCenterY + mInnerRadius * (float) Math.sin(mFingerRadians), - mCenterX - zoomRadius * (float) Math.cos(mFingerRadians), - mCenterY + zoomRadius * (float) Math.sin(mFingerRadians), mPaint); - } - - @Override - public boolean onScale(ScaleGestureDetector detector) { - final float sf = detector.getScaleFactor(); - mCurrentFraction = (0.33f + mCurrentFraction) * sf * sf - 0.33f; - if (mCurrentFraction < 0.0f) mCurrentFraction = 0.0f; - if (mCurrentFraction > 1.0f) mCurrentFraction = 1.0f; - int newIndex = mMinIndex + (int) (mCurrentFraction * (mMaxIndex - mMinIndex)); - if (mListener != null && newIndex != mCurrentIndex) { - mListener.onZoomValueChanged(newIndex); - mCurrentIndex = newIndex; - } - // mFingerRadians is currently constrained to [0,Pi/2]. - // TODO: Get actual touch coordinates to enable full [0,Pi] range. - mFingerRadians = Math.atan2(detector.getCurrentSpanY(),detector.getCurrentSpanX()); - return true; - } - - @Override - public boolean onScaleBegin(ScaleGestureDetector detector) { - setVisible(true); - if (mListener != null) { - mListener.onZoomStart(); - } - update(); - return true; - } - - @Override - public void onScaleEnd(ScaleGestureDetector detector) { - setVisible(false); - if (mListener != null) { - mListener.onZoomEnd(); - } - } - -} |