diff options
author | Michael Kolb <kolby@google.com> | 2011-03-16 16:06:03 -0700 |
---|---|---|
committer | Michael Kolb <kolby@google.com> | 2011-03-16 16:14:44 -0700 |
commit | 565752e1025129ad16c030ceca9dee7a695ed73e (patch) | |
tree | 4131b60d56f3783ba7c68db0f8e8dcac7aafbaa4 /src/com/android | |
parent | 1c699aabc351e44869c4e6c4e06e6c1ebcc0613a (diff) | |
download | packages_apps_Browser-565752e1025129ad16c030ceca9dee7a695ed73e.zip packages_apps_Browser-565752e1025129ad16c030ceca9dee7a695ed73e.tar.gz packages_apps_Browser-565752e1025129ad16c030ceca9dee7a695ed73e.tar.bz2 |
fix quick control rendering
Bug: 4108815
render pie slices again, use faded background
Change-Id: I05e5bf2f6809d5775b48f22a67b37e961aa5ab9f
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/browser/PieControl.java | 6 | ||||
-rw-r--r-- | src/com/android/browser/view/BasePieView.java | 2 | ||||
-rw-r--r-- | src/com/android/browser/view/PieItem.java | 9 | ||||
-rw-r--r-- | src/com/android/browser/view/PieListView.java | 4 | ||||
-rw-r--r-- | src/com/android/browser/view/PieMenu.java | 91 | ||||
-rw-r--r-- | src/com/android/browser/view/PieStackView.java | 7 |
6 files changed, 91 insertions, 28 deletions
diff --git a/src/com/android/browser/PieControl.java b/src/com/android/browser/PieControl.java index ed3e960..38ed1bb 100644 --- a/src/com/android/browser/PieControl.java +++ b/src/com/android/browser/PieControl.java @@ -26,8 +26,6 @@ import com.android.browser.view.PieStackView.OnCurrentListener; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.os.Handler; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -165,7 +163,6 @@ public class PieControl implements OnClickListener, PieMenu.PieController { image.setScaleType(ScaleType.CENTER); LayoutParams lp = new LayoutParams(mItemSize, mItemSize); v.setLayoutParams(lp); - v.setBackgroundResource(R.drawable.qc_item_selector); return v; } @@ -175,9 +172,8 @@ public class PieControl implements OnClickListener, PieMenu.PieController { view.setMinimumWidth(mItemSize); view.setMinimumHeight(mItemSize); view.setScaleType(ScaleType.CENTER); - LayoutParams lp = new LayoutParams(mItemSize,mItemSize); + LayoutParams lp = new LayoutParams(mItemSize, mItemSize); view.setLayoutParams(lp); - view.setBackgroundResource(R.drawable.qc_item_selector); return new PieItem(view, l); } diff --git a/src/com/android/browser/view/BasePieView.java b/src/com/android/browser/view/BasePieView.java index 2120215..ec02e3a 100644 --- a/src/com/android/browser/view/BasePieView.java +++ b/src/com/android/browser/view/BasePieView.java @@ -109,7 +109,7 @@ public abstract class BasePieView implements PieMenu.PieView { * needs to set top, left, width, height */ @Override - public void layout(int anchorX, int anchorY, boolean left) { + public void layout(int anchorX, int anchorY, boolean left, float angle) { if (mListener != null) { mListener.onLayout(anchorX, anchorY, left); } diff --git a/src/com/android/browser/view/PieItem.java b/src/com/android/browser/view/PieItem.java index 84a6ac0..3674447 100644 --- a/src/com/android/browser/view/PieItem.java +++ b/src/com/android/browser/view/PieItem.java @@ -18,6 +18,7 @@ package com.android.browser.view; import com.android.browser.view.PieMenu.PieView; +import android.graphics.Path; import android.view.View; /** @@ -33,6 +34,7 @@ public class PieItem { private int inner; private int outer; private boolean mSelected; + private Path mPath; public PieItem(View view, int level) { mView = view; @@ -60,11 +62,12 @@ public class PieItem { return level; } - public void setGeometry(float st, float sw, int inside, int outside) { + public void setGeometry(float st, float sw, int inside, int outside, Path p) { start = st; sweep = sw; inner = inside; outer = outside; + mPath = p; } public float getStartAngle() { @@ -99,4 +102,8 @@ public class PieItem { return mPieView; } + public Path getPath() { + return mPath; + } + } diff --git a/src/com/android/browser/view/PieListView.java b/src/com/android/browser/view/PieListView.java index 8cd8a4e..04b512b 100644 --- a/src/com/android/browser/view/PieListView.java +++ b/src/com/android/browser/view/PieListView.java @@ -39,8 +39,8 @@ public class PieListView extends BasePieView { * this will be called before the first draw call */ @Override - public void layout(int anchorX, int anchorY, boolean left) { - super.layout(anchorX, anchorY, left); + public void layout(int anchorX, int anchorY, boolean left, float angle) { + super.layout(anchorX, anchorY, left, angle); buildViews(); mWidth = mChildWidth; mHeight = mChildHeight * mAdapter.getCount(); diff --git a/src/com/android/browser/view/PieMenu.java b/src/com/android/browser/view/PieMenu.java index e494d19..cded435 100644 --- a/src/com/android/browser/view/PieMenu.java +++ b/src/com/android/browser/view/PieMenu.java @@ -21,8 +21,11 @@ import com.android.browser.R; import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Path; import android.graphics.Point; import android.graphics.PointF; +import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.MotionEvent; @@ -57,7 +60,7 @@ public class PieMenu extends FrameLayout { public void setLayoutListener(OnLayoutListener l); - public void layout(int anchorX, int anchorY, boolean onleft); + public void layout(int anchorX, int anchorY, boolean onleft, float angle); public void draw(Canvas c); @@ -69,6 +72,7 @@ public class PieMenu extends FrameLayout { private int mRadius; private int mRadiusInc; private int mSlop; + private int mTouchOffset; private boolean mOpen; private PieController mController; @@ -79,6 +83,8 @@ public class PieMenu extends FrameLayout { private PieView mPieView = null; private Drawable mBackground; + private Paint mNormalPaint; + private Paint mSelectedPaint; // touch handling PieItem mCurrentItem; @@ -118,11 +124,18 @@ public class PieMenu extends FrameLayout { mRadius = (int) res.getDimension(R.dimen.qc_radius_start); mRadiusInc = (int) res.getDimension(R.dimen.qc_radius_increment); mSlop = (int) res.getDimension(R.dimen.qc_slop); + mTouchOffset = (int) res.getDimension(R.dimen.qc_touch_offset); mOpen = false; setWillNotDraw(false); setDrawingCacheEnabled(false); mCenter = new Point(0,0); mBackground = res.getDrawable(R.drawable.qc_background_normal); + mNormalPaint = new Paint(); + mNormalPaint.setColor(res.getColor(R.color.qc_normal)); + mNormalPaint.setAntiAlias(true); + mSelectedPaint = new Paint(); + mSelectedPaint.setColor(res.getColor(R.color.qc_selected)); + mSelectedPaint.setAntiAlias(true); } public void setController(PieController ctl) { @@ -178,13 +191,16 @@ public class PieMenu extends FrameLayout { } private void layoutPie() { - int inner = mRadius; - int outer = mRadius + mRadiusInc; + float emptyangle = (float) Math.PI / 16; + int rgap = 2; + int inner = mRadius + rgap; + int outer = mRadius + mRadiusInc - rgap; int radius = mRadius; + int gap = 1; for (int i = 0; i < mLevels; i++) { int level = i + 1; - float sweep = (float) Math.PI / (mCounts[level] + 1); - float angle = sweep; + float sweep = (float) (Math.PI - 2 * emptyangle) / mCounts[level]; + float angle = emptyangle + sweep / 2; for (PieItem item : mItems) { if (item.getLevel() == level) { View view = item.getView(); @@ -192,16 +208,20 @@ public class PieMenu extends FrameLayout { view.getLayoutParams().height); int w = view.getMeasuredWidth(); int h = view.getMeasuredHeight(); - int x = (int) (outer * Math.sin(angle)); - int y = mCenter.y - (int) (outer * Math.cos(angle)) - h / 2; + int r = inner + (outer - inner) * 2 / 3; + int x = (int) (r * Math.sin(angle)); + int y = mCenter.y - (int) (r * Math.cos(angle)) - h / 2; if (onTheLeft()) { - x = mCenter.x + x - w; + x = mCenter.x + x - w / 2; } else { - x = mCenter.x - x; + x = mCenter.x - x - w / 2; } view.layout(x, y, x + w, y + h); float itemstart = angle - sweep / 2; - item.setGeometry(itemstart, sweep, inner, outer); + Path slice = makeSlice(getDegrees(itemstart) - gap, + getDegrees(itemstart + sweep) + gap, + outer, inner, mCenter); + item.setGeometry(itemstart, sweep, inner, outer, slice); angle += sweep; } } @@ -210,6 +230,18 @@ public class PieMenu extends FrameLayout { } } + + /** + * 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) (270 - 180 * angle / Math.PI); + } + @Override protected void onDraw(Canvas canvas) { if (mOpen) { @@ -218,13 +250,21 @@ public class PieMenu extends FrameLayout { int left = mCenter.x - w; int top = mCenter.y - h / 2; mBackground.setBounds(left, top, left + w, top + h); - int state = canvas.save(); + int state; + state = canvas.save(); if (onTheLeft()) { canvas.scale(-1, 1); } mBackground.draw(canvas); canvas.restoreToCount(state); for (PieItem item : mItems) { + Paint p = item.isSelected() ? mSelectedPaint : mNormalPaint; + state = canvas.save(); + if (onTheLeft()) { + canvas.scale(-1, 1); + } + drawPath(canvas, item.getPath(), p); + canvas.restoreToCount(state); drawItem(canvas, item); } if (mPieView != null) { @@ -245,6 +285,24 @@ public class PieMenu extends FrameLayout { canvas.restoreToCount(state); } + private void drawPath(Canvas canvas, Path path, Paint paint) { + canvas.drawPath(path, paint); + } + + private Path makeSlice(float start, float end, int outer, int inner, Point center) { + RectF bb = + new RectF(center.x - outer, center.y - outer, center.x + outer, + center.y + outer); + RectF bbi = + new RectF(center.x - inner, center.y - inner, center.x + inner, + center.y + inner); + Path path = new Path(); + path.arcTo(bb, start, end - start, true); + path.arcTo(bbi, end, start - end); + path.close(); + return path; + } + // touch handling for pie @Override @@ -307,7 +365,8 @@ public class PieMenu extends FrameLayout { ? item.getView().getWidth() : 0); int cy = item.getView().getTop(); mPieView = item.getPieView(); - layoutPieView(mPieView, cx, cy); + layoutPieView(mPieView, cx, cy, + (item.getStartAngle() + item.getSweep()) / 2); } invalidate(); } @@ -316,8 +375,8 @@ public class PieMenu extends FrameLayout { return false; } - private void layoutPieView(PieView pv, int x, int y) { - pv.layout(x, y, onTheLeft()); + private void layoutPieView(PieView pv, int x, int y, float angle) { + pv.layout(x, y, onTheLeft(), angle); } /** @@ -373,8 +432,8 @@ public class PieMenu extends FrameLayout { private PieItem findItem(PointF polar) { // find the matching item: for (PieItem item : mItems) { - if ((item.getInnerRadius() < polar.y) - && (item.getOuterRadius() > polar.y) + if ((item.getInnerRadius() - mTouchOffset < polar.y) + && (item.getOuterRadius() - mTouchOffset > polar.y) && (item.getStartAngle() < polar.x) && (item.getStartAngle() + item.getSweep() > polar.x)) { return item; diff --git a/src/com/android/browser/view/PieStackView.java b/src/com/android/browser/view/PieStackView.java index df387ad..ca641f9 100644 --- a/src/com/android/browser/view/PieStackView.java +++ b/src/com/android/browser/view/PieStackView.java @@ -59,8 +59,8 @@ public class PieStackView extends BasePieView { * this will be called before the first draw call */ @Override - public void layout(int anchorX, int anchorY, boolean left) { - super.layout(anchorX, anchorY, left); + public void layout(int anchorX, int anchorY, boolean left, float angle) { + super.layout(anchorX, anchorY, left, angle); buildViews(); mWidth = mChildWidth; mHeight = mChildHeight + (mViews.size() - 1) * mMinHeight; @@ -76,7 +76,8 @@ public class PieStackView extends BasePieView { int top = mTop; int dy = (n == 1) ? 0 : (mHeight - mChildHeight) / (n - 1); for (View view : mViews) { - view.layout(mLeft, top, mLeft + mChildWidth, top + mChildHeight); + int x = mLeft; + view.layout(x, top, x + mChildWidth, top + mChildHeight); top += dy; } } |